cmark

My personal build of CMark ✏️

Commit
eea23326c89875d6737e6bbeec7f7b201ed36d03
Parent
ef487406436407320a54273d5668bf1520e08d67
Author
John MacFarlane <jgm@berkeley.edu>
Date

Handle more attributes with xml.js.

Diffstat

1 file changed, 50 insertions, 26 deletions

Status File Name N° Changes Insertions Deletions
Modified js/lib/xml.js 76 50 26
diff --git a/js/lib/xml.js b/js/lib/xml.js
@@ -61,49 +61,73 @@ var renderNodes = function(block) {
 
     if (options.time) { console.time("rendering"); }
 
+    buffer += '<?xml version="1.0" encoding="UTF-8"?>\n';
+    buffer += '<!DOCTYPE CommonMark SYSTEM "CommonMark.dtd">\n';
+
     while ((event = walker.next())) {
         entering = event.entering;
         node = event.node;
+
+        if (node.t === 'ReferenceDef') {
+            continue;
+        }
+
         container = node.isContainer();
         selfClosing = node.t === 'HorizontalRule' || node.t === 'Hardbreak' ||
             node.t === 'Softbreak' || node.t === 'Image';
         unescapedContents = node.t === 'Html' || node.t === 'HtmlInline';
         tagname = node.t.toLowerCase();
 
-        attrs = [];
+        if (entering) {
+
+            attrs = [];
+
+            if (node.list_data) {
+                var data = node.list_data;
+                if (data.type) {
+                    attrs.push(['type', data.type.toLowerCase()]);
+                }
+                if (data.start) {
+                    attrs.push(['start', String(data.start)]);
+                }
+                if (data.tight) {
+                    attrs.push(['tight', (data.tight ? 'true' : 'false')]);
+                }
+                if (data.delimiter) {
+                    var delimword = '';
+                    if (data.delimiter === '.') {
+                        delimword = 'period';
+                    } else {
+                        delimword = 'paren';
+                    }
+                    attrs.push(['delimiter', delimword]);
+                }
+            }
 
-        if (node.list_data) {
-            var data = node.list_data;
-            if (data.type) {
-                attrs.push(['type', data.type.toLowerCase()]);
+            if (node.info) {
+                attrs.push(['info', node.info]);
             }
-            if (data.start) {
-                attrs.push(['start', String(data.start)]);
+            if (node.level) {
+                attrs.push(['level', String(node.level)]);
             }
-            if (data.tight) {
-                attrs.push(['tight', (data.tight ? 'true' : 'false')]);
+            if (node.url) {
+                attrs.push(['url', node.url]);
             }
-            if (data.delimiter) {
-                var delimword = '';
-                if (data.delimiter === '.') {
-                  delimword = 'period';
-                } else {
-                  delimword = 'paren';
-                }
-                attrs.push(['delimiter', delimword]);
+            if (node.title) {
+                attrs.push(['title', node.title]);
             }
-        }
 
-        if (options.sourcepos) {
-            var pos = node.sourcepos;
-            if (pos) {
-                attrs.push(['data-sourcepos', String(pos[0][0]) + ':' +
-                            String(pos[0][1]) + '-' + String(pos[1][0]) + ':' +
-                            String(pos[1][1])]);
+            if (options.sourcepos) {
+                var pos = node.sourcepos;
+                if (pos) {
+                    attrs.push(['data-sourcepos', String(pos[0][0]) + ':' +
+                                String(pos[0][1]) + '-' + String(pos[1][0]) + ':' +
+                                String(pos[1][1])]);
+                }
             }
-        }
 
-        if (entering) {
+
+
             cr();
             out(tag(tagname, attrs, selfClosing));
             if (container) {