From eea23326c89875d6737e6bbeec7f7b201ed36d03 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 11 Jan 2015 18:20:23 -0800 Subject: Handle more attributes with xml.js. --- js/lib/xml.js | 76 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 26 deletions(-) (limited to 'js') diff --git a/js/lib/xml.js b/js/lib/xml.js index cb59d7b..ea98d82 100644 --- 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 += '\n'; + buffer += '\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) { -- cgit v1.2.3