From 3b3c5c9502252a2ce13a7daffa80da2709d586e1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 11 Jan 2015 21:04:45 -0800 Subject: More xml.js improvements. --- js/lib/xml.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/js/lib/xml.js b/js/lib/xml.js index c90704e..30b44c8 100644 --- 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) { -- cgit v1.2.3