- Commit
- 3b3c5c9502252a2ce13a7daffa80da2709d586e1
- Parent
- 5e2e9034f13438ad6286ab09d49cfe425f06090c
- Author
- John MacFarlane <jgm@berkeley.edu>
- Date
More xml.js improvements.
My personal build of CMark ✏️
More xml.js improvements.
1 file changed, 19 insertions, 18 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | js/lib/xml.js | 37 | 19 | 18 |
diff --git a/js/lib/xml.js b/js/lib/xml.js @@ -41,6 +41,7 @@ var renderNodes = function(block) { var unescapedContents; var container; var selfClosing; + var nodetype; var out = function(s) { if (disableTags > 0) { @@ -71,22 +72,24 @@ var renderNodes = function(block) { while ((event = walker.next())) { entering = event.entering; node = event.node; + nodetype = node.t; - if (node.t === 'ReferenceDef') { + if (nodetype === '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 = toTagName(node.t); + selfClosing = nodetype === 'HorizontalRule' || nodetype === 'Hardbreak' || + nodetype === 'Softbreak' || nodetype === 'Image'; + unescapedContents = nodetype === 'Html' || nodetype === 'HtmlInline'; + tagname = toTagName(nodetype); if (entering) { attrs = []; - if (node.list_data) { + switch (nodetype) { + case 'List': var data = node.list_data; if (data.type !== undefined) { attrs.push(['type', data.type.toLowerCase()]); @@ -106,21 +109,21 @@ var renderNodes = function(block) { } attrs.push(['delimiter', delimword]); } - } - - if (node.info !== undefined) { + break; + case 'CodeBlock': attrs.push(['info', node.info]); - } - if (node.level !== undefined) { + break; + case 'Header': attrs.push(['level', String(node.level)]); - } - if (node.destination !== undefined) { + break; + case 'Link': + case 'Image': attrs.push(['destination', node.destination]); - } - if (node.title !== undefined) { attrs.push(['title', node.title]); + break; + default: + break; } - if (options.sourcepos) { var pos = node.sourcepos; if (pos !== undefined) { @@ -130,8 +133,6 @@ var renderNodes = function(block) { } } - - cr(); out(tag(tagname, attrs, selfClosing)); if (container) {