Skip to content
Browse files

Fixed CLI bug with missing paths. Now returning class names for close…

…d states in parseToken calls
  • Loading branch information...
1 parent 74586f2 commit fc5e0f73eb60a4587184c8ec93c365d381b51b06 @cgiffard committed Sep 11, 2012
Showing with 41 additions and 18 deletions.
  1. +21 −9 compiled/duckdown-unminified.js
  2. +2 −2 compiled/duckdown.js
  3. +1 −1 lib/cli.js
  4. +17 −6 lib/duckdown.js
View
30 compiled/duckdown-unminified.js
@@ -3,7 +3,7 @@
// Christopher Giffard 2012
//
//
-// Package built Fri Aug 31 2012 15:15:40 GMT+1000 (EST)
+// Package built Tue Sep 11 2012 15:09:22 GMT+1000 (EST)
//
@@ -13,8 +13,9 @@
function require(input) {
return window[({
"./ducknode.js": "DuckdownNode",
- "./index.js": "Duckdown",
- "./grammar.js": "DuckdownGrammar"
+ "./duckdown.js": "Duckdown",
+ "./grammar.js": "DuckdownGrammar",
+ "../grammar": "DuckdownGrammar"
})[input]];
}
@@ -1539,7 +1540,8 @@ you see in the /grammar folder.
};
Duckdown.prototype.parseToken = function(state, input) {
- var currentState, newState, tokenGenus, stateGenus, tree;
+ var currentState, newState, tokenGenus, stateGenus, tree,
+ closedNodeStates = [], closedNodeState;
if (this instanceof Duckdown) state = this;
@@ -1693,11 +1695,17 @@ you see in the /grammar folder.
// We'll leave it up to the state genus can determine what to do if
// it's mismatched - we're not going to be presumptuous!
state.currentNode.mismatched = true;
- state.closeCurrentNode(true);
+ closedNodeState = state.closeCurrentNode(true);
+
+ if (closedNodeState && closedNodeState.length)
+ closedNodeStates = closedNodeStates.concat(closedNodeState);
}
// And now close the actual node we're supposed to be listening for...
- state.closeCurrentNode();
+ closedNodeState = state.closeCurrentNode();
+
+ if (closedNodeState && closedNodeState.length)
+ closedNodeStates = closedNodeStates.concat(closedNodeState);
}
}
@@ -1858,7 +1866,7 @@ you see in the /grammar folder.
state.previousToken = state.currentToken;
// Return parser states for this token as a css-compatible class string.
- return state.parserStates.join(" ").toLowerCase().replace(/\_/ig,"-");
+ return state.parserStates.concat(closedNodeStates).join(" ").toLowerCase().replace(/\_/ig,"-");
};
// Compile from Duckdown intermediate format to the destination text format.
@@ -1959,7 +1967,8 @@ you see in the /grammar folder.
// Function for closing nodes...
Duckdown.prototype.closeCurrentNode = function(parentNodeClosed) {
var currentState = this.parserStates[this.parserStates.length-1],
- stateGenus = Grammar.stateList[currentState];
+ stateGenus = Grammar.stateList[currentState],
+ closedStateList = [];
var state = this, tmpTokenGenus = {}, tree = null;
@@ -2097,7 +2106,8 @@ you see in the /grammar folder.
state.nodeDepth --;
// Truncate parser state stack...
- state.parserStates.length = state.nodeDepth;
+ if (state.nodeDepth < state.parserStates.length)
+ closedStateList = state.parserStates.splice(state.nodeDepth - state.parserStates.length);
// Finally, do we swallow any token components that match?
// Check the state genus and act accordingly. If we destroy the token components,
@@ -2129,6 +2139,8 @@ you see in the /grammar folder.
state.currentToken = state.currentToken.substring(matchPoint);
}
}
+
+ return closedStateList;
};
// Helper function to do a reverse-lookup to find token info from a state name.
View
4 compiled/duckdown.js
@@ -3,8 +3,8 @@
// Christopher Giffard 2012
//
//
-// Package built Fri Aug 31 2012 15:15:40 GMT+1000 (EST)
+// Package built Tue Sep 11 2012 15:09:22 GMT+1000 (EST)
//
-(function(e){function t(e){return window[{"./ducknode.js":"DuckdownNode","./index.js":"Duckdown","./grammar.js":"DuckdownGrammar"}[e]]}(function(e){"use strict";var t={};t.wordCharacters=/[a-z0-9 ]/ig,t.escapeCharacters=/[^a-z0-9\s\-\_\:\\\/\=\%\~\`\!\@\#\$\*\(\)\+\[\]\{\}\|\;\,\.\?\']/ig,t.replacer=function(e,t,n){return e==="&"?"&amp;":e==="<"?"&lt;":e===">"?"&gt;":e==='"'?"&quot;":"&#x"+e.charCodeAt(0).toString(16)+";"},t.tokenMappings={"\n":{wrapper:!0,swallowTokens:!1,exit:/\n/,state:"IMPLICIT_BREAK",semanticLevel:"hybrid"}," ":{wrapper:!0,swallowTokens:!1,exit:/\n/,state:"IMPLICIT_INDENT",semanticLevel:"hybrid",allowSelfNesting:!0}," ":{wrapper:!0,swallowTokens:!1,exit:/\n/,state:"IMPLICIT_INDENT",semanticLevel:"hybrid",allowSelfNesting:!0},"&":{wrapper:!1,exit:/([^#a-z0-9]|;)/i,validIf:/^&#?[a-z0-9]+;$/ig,state:"ENTITY",semanticLevel:"text"},"~":{semanticLevel:"text",wrapper:!0,allowSelfNesting:!1,exit:/[\~\n]/,validIf:/^\~\S[^\n]+\S\~$/,state:"TEXT_EMPHASIS"},"*":{semanticLevel:"text",wrapper:!0,allowSelfNesting:!1,exit:/[\*\n]/,validIf:/^\*\S[^\n]+\S\*$/,state:"TEXT_STRONG"},"-":{state:"TEXT_DEL",wrapper:!0,semanticLevel:"text",exit:/[\-\n]/,validIf:/^\-\S[^\n]+\S\-$/,blankPrevSibling:!0},_:{wrapper:!0,semanticLevel:"text",exit:/[_\n]/,validIf:/^\_\S[^\n]+\S\_$/,state:"TEXT_UNDERLINE"},"<":{wrapper:!1,semanticLevel:"hybrid",exit:/[>\n]/,validIf:/^<[a-z][a-z0-9\-\_]*(\s[^>\n]+)*>$/i,state:"SPECIAL_FEATHER"},"`":{wrapper:!1,semanticLevel:"text",exit:/[`\n]/,state:"CODE_LITERAL"},'"':{wrapper:!1,semanticLevel:"text",exit:/["\n]/,validIf:/^\".*\"$/,state:"TEXT_QUOTE"},"* ":{wrapper:!0,exit:/\n/i,state:"LIST_UNORDERED",semanticLevel:"textblock",swallowTokens:!1},"* ":{wrapper:!0,exit:/\n/i,state:"LIST_UNORDERED",semanticLevel:"textblock",swallowTokens:!1},". ":{wrapper:!0,exit:/\n/i,state:"LIST_ORDERED",semanticLevel:"textblock",swallowTokens:!1},". ":{wrapper:!0,exit:/\n/i,state:"LIST_ORDERED",semanticLevel:"textblock",swallowTokens:!1},">":{wrapper:!0,exit:/\n/i,state:"BLOCKQUOTE",semanticLevel:"block",allowSelfNesting:"true",swallowTokens:!1,mustBeFirstChild:!0},"h1.":{wrapper:!0,exit:/\n/i,state:"HEADING_1",semanticLevel:"textblock"},"h2.":{wrapper:!0,exit:/\n/i,state:"HEADING_2",semanticLevel:"textblock"},"h3.":{wrapper:!0,exit:/\n/i,state:"HEADING_3",semanticLevel:"textblock"},"h4.":{wrapper:!0,exit:/\n/i,state:"HEADING_4",semanticLevel:"textblock"},"h5.":{wrapper:!0,exit:/\n/i,state:"HEADING_5",semanticLevel:"textblock"},"h6.":{wrapper:!0,exit:/\n/i,state:"HEADING_6",semanticLevel:"textblock"},"http://":{state:"AUTO_LINK",wrapper:!1,exit:/[^a-z0-9\-_\.\~\!\*\'\(\)\;\:\@\&\=\+\$\,\/\?\%\#\[\]\#]/i,validIf:/^http[s]?:\/\/[a-z0-9\-\.]+(\:\d+)?.*$/i,swallowTokens:!1,swallowWhitespace:!0,semanticLevel:"text"},"https://":{state:"AUTO_LINK",wrapper:!1,exit:/[^a-z0-9\-_\.\~\!\*\'\(\)\;\:\@\&\=\+\$\,\/\?\%\#\[\]\#]/i,validIf:/^http[s]?:\/\/[a-z0-9\-\.]+(\:\d+)?.*$/i,swallowTokens:!1,swallowWhitespace:!0,semanticLevel:"text"},"(":{state:"PAREN_DESCRIPTOR",wrapper:!0,exit:/(\s\s+|\n|\))/,validIf:/^\([^\n]+\)$/,allowSelfNesting:!0,semanticLevel:"text"},"-- ":{state:"CITATION",exit:/\n/,wrapper:!0,semanticLevel:"text",swallowTokens:!1},"--":{state:"HORIZONTAL_RULE",wrapper:!1,exit:/[^\-]/i,validIf:/^\-\-+\n*$/i,semanticLevel:"block",swallowTokens:!1}},t.stateList={ENTITY:{process:function(){},compile:function(e,t){var n=e.children[e.children.length-1];return e.exitToken===";"?"&"+e.children.join("")+";":typeof n=="string"&&n.match(/\;/)?"&"+e.children.join(""):"&amp;"+t(e)}},IMPLICIT_BREAK:{process:function(e){if(!e.text().length&&!e.blockParent)return!1;for(var t=0;t<e.children.length;t++)if(e.children[t].state==="IMPLICIT_INDENT"){e.blockParent=!0;break}},compile:function(e,t){var n=t(e),r=!e.blockParent;if(r){var i=!1,s=!1;if(!e.previousSibling||e.prevSiblingCulled&&e.prevCulledSiblingState==="IMPLICIT_BREAK"||e.previousSibling.blockParent)i=!0;if(!e.nextSibling||e.nextSiblingCulled&&e.nextCulledSiblingState==="IMPLICIT_BREAK")s=!0;e.nextSibling&&(e.nextSibling.blockParent||!e.nextSibling.children.length)&&(s=!0);var o=n.match(/\s+$/i)?"":" ";return i&&(n="<p>"+n),n+=s?"</p>\n":o,n}return n+"\n"}},IMPLICIT_INDENT:{process:function(e){if(!e.text().length)return!1},compile:function(e,t){var n=!1;if(!e.parent||e.previousSibling||e.parent.state==="IMPLICIT_BREAK"||e.parent.semanticLevel==="block"||e.parent.semanticLevel==="hybrid")e.parent?!e.parent.previousSibling&&!e.previousSibling&&e.parent.state!=="IMPLICIT_INDENT"?n=!0:e.parent.prevSiblingCulled&&e.parent.prevCulledSiblingState==="IMPLICIT_BREAK"&&(n=!0):n=!0;return n?"<pre>"+e.raw(!0).replace(/^\s+/,"")+"</pre>\n":t(e)}},TEXT_EMPHASIS:{compile:function(e,t){return"<em>"+t(e)+"</em>"}},TEXT_STRONG:{compile:function(e,t){return"<strong>"+t(e)+"</strong>"}},TEXT_DEL:{process:function(e){return e.previousSibling?typeof e.previousSibling=="string"&&e.previousSibling.match(/\s$/g)?!0:typeof e.previousSibling=="object"?!0:-1:!0},compile:function(e,t){return"<del>"+t(e)+"</del>"}},TEXT_QUOTE:{process:function(e){if(e.parent&&!e.parent.prevSiblingCulled&&e.parent.previousSibling&&e.parent.previousSibling.state===e.parent.state)return-1},compile:function(e,t){return"<q>"+t(e)+"</q>"}},TEXT_UNDERLINE:{compile:function(e,t){return"<u>"+t(e)+"</u>"}},CODE_LITERAL:{compile:function(e,t){return"<code>"+e.text()+"</code>"}},LIST_UNORDERED:{process:function(e){if(e.previousSibling)return-1;if(!e.parent)return-1;if(e.parent.previousSibling&&typeof e.parent.previousSibling=="object"&&e.parent.previousSibling.state!==e.parent.state&&!e.parent.prevSiblingCulled)return-1;if(e.rootBlock&&e.rootBlock.previousSibling&&!e.rootBlock.prevSiblingCulled&&e.rootBlock.previousSibling.blockType!==e.state&&e.rootBlock.previousSibling.blockType!=="LIST_ORDERED")return-1;var t=e,n=0;while(t)t.state==="IMPLICIT_INDENT"&&n++,t=t.parent;e.indentation=n;if(e.rootBlock&&e.rootBlock.previousSibling&&e.rootBlock.previousSibling.blockNode&&(e.rootBlock.previousSibling.semanticLevel==="hybrid"||e.rootBlock.previousSibling.semanticLevel==="textblock"||e.rootBlock.previousSibling.semanticLevel==="block")&&e.rootBlock.previousSibling.blockNode.indentation<e.indentation){var r=e.rootBlock.previousSibling.blockNode;while(r.children.length&&typeof r.children[r.children.length-1]=="object"&&(r.children[r.children.length-1].semanticLevel==="hybrid"||r.children[r.children.length-1].semanticLevel==="textblock"||r.children[r.children.length-1].semanticLevel==="block")){if(r.children[r.children.length-1].indentation!==null&&r.children[r.children.length-1].indentation>=e.indentation)break;r=r.children[r.children.length-1]}r.children.push(e),r.blockParent=!0,e.rootBlock.remove(),r.updateIndices(),r.children[e.index-1]&&(typeof r.children[e.index-1]!="object"||r.children[e.index-1].state!==e.state)&&(e.breakBefore=!0)}},compile:function(e,t){var n="";e.breakBefore&&(n+="\n");if(!e.parent.previousSibling||e.parent.prevSiblingCulled||!e.parent.previousSibling.blockParent||!e.parent.previousSibling.children.length||e.parent.previousSibling.children[0].state!=="LIST_UNORDERED"&&e.parent.previousSibling.children[0].state!=="IMPLICIT_INDENT")n+="<ul>\n";n+="<li>"+t(e)+"</li>\n";if(!e.parent.nextSibling||e.parent.nextSiblingCulled||!e.parent.nextSibling.blockParent||!e.parent.nextSibling.children.length||e.parent.nextSibling.children[0].state!=="LIST_UNORDERED"&&e.parent.nextSibling.children[0].state!=="IMPLICIT_INDENT")n+="</ul>\n";return n}},LIST_ORDERED:{process:function(e){if(e.previousSibling&&(typeof e.previousSibling=="object"||e.previousSibling.match(/[^a-z0-9]/g)))return-1;if(!e.parent)return-1;if(e.parent.previousSibling&&typeof e.parent.previousSibling=="object"&&e.parent.previousSibling.state!==e.parent.state&&!e.parent.prevSiblingCulled)return-1;if(e.rootBlock&&e.rootBlock.previousSibling&&!e.rootBlock.prevSiblingCulled&&e.rootBlock.previousSibling.blockType!==e.state&&e.rootBlock.previousSibling.blockType!=="LIST_UNORDERED")return-1;if(e.previousSibling&&e.previousSibling.match(/^[a-z0-9]+$/)&&e.index<2){e.listQualifier=e.previousSibling,e.parent.removeChild(e.index-1);var t=e,n=0;while(t)t.state==="IMPLICIT_INDENT"&&n++,t=t.parent;e.indentation=n;if(e.rootBlock&&e.rootBlock.previousSibling&&e.rootBlock.previousSibling.blockNode&&(e.rootBlock.previousSibling.semanticLevel==="hybrid"||e.rootBlock.previousSibling.semanticLevel==="textblock"||e.rootBlock.previousSibling.semanticLevel==="block")&&e.rootBlock.previousSibling.blockNode.indentation<e.indentation){var r=e.rootBlock.previousSibling.blockNode;while(r.children.length&&typeof r.children[r.children.length-1]=="object"&&(r.children[r.children.length-1].semanticLevel==="hybrid"||r.children[r.children.length-1].semanticLevel==="textblock"||r.children[r.children.length-1].semanticLevel==="block")){if(r.children[r.children.length-1].indentation!==null&&r.children[r.children.length-1].indentation>=e.indentation)break;r=r.children[r.children.length-1]}r.children.push(e),r.blockParent=!0,e.rootBlock.remove(),r.updateIndices(),r.children[e.index-1]&&(typeof r.children[e.index-1]!="object"||r.children[e.index-1].state!==e.state)&&(e.breakBefore=!0)}return!0}return-1},compile:function(e,t){var n="";e.breakBefore&&(n+="\n");if(!e.parent.previousSibling||e.parent.prevSiblingCulled||!e.parent.previousSibling.blockParent||!e.parent.previousSibling.children.length||e.parent.previousSibling.children[0].state!=="LIST_ORDERED"&&e.parent.previousSibling.children[0].state!=="IMPLICIT_INDENT"){var r="";e.listQualifier.match(/[ivxcmd]/ig)?r="lower-roman":e.listQualifier.match(/[a-z]/ig)&&(r="lower-alpha"),r=r.length?' style="list-style: '+r+';"':"",n+="<ol"+r+">\n"}n+="<li>"+t(e)+(e.blockParent?"\n":"")+"</li>\n";if(!e.parent.nextSibling||e.parent.nextSiblingCulled||!e.parent.nextSibling.blockParent||!e.parent.nextSibling.children.length||e.parent.nextSibling.children[0].state!=="LIST_ORDERED"&&e.parent.nextSibling.children[0].state!=="IMPLICIT_INDENT")n+="</ol>\n";return n}},BLOCKQUOTE:{process:function(e){if(e.previousSibling)return-1;var t=0,n=e,r;while(n)n.state===e.state&&t++,n=n.parent;e.indentation=t;if(e.rootBlock&&e.rootBlock.previousSibling&&(!e.rootBlock.prevSiblingCulled||e.rootBlock.prevCulledSiblingState===e.state)&&e.rootBlock.previousSibling.blockType===e.state&&e.rootBlock.previousSibling.blockNode){e.rootBlock.previousSibling.blockNode.indentation<e.indentation,n=e.rootBlock.previousSibling.blockNode;while(n&&!r)n.indentation<e.indentation&&(r=n),n=n.parent;if(r){var i=e.rootBlock,s=i.previousSibling;i.remove(),i.children=e.children,e.children=[i],s.blockNode.children.push(e)}}},compile:function(e,t){var n="";if(!e.parent.previousSibling||e.parent.prevSiblingCulled||!e.parent.previousSibling.blockParent||!e.parent.previousSibling.children.length||e.parent.previousSibling.children[0].state!=="BLOCKQUOTE"&&e.parent.previousSibling.children[0].state!=="IMPLICIT_INDENT")n+="<blockquote>\n";var r=t(e);r.length&&(e.blockParent||(n+="<p>"),n+=r,e.blockParent||(n+="</p>\n"));if(!e.parent.nextSibling||e.parent.nextSiblingCulled||!e.parent.nextSibling.blockParent||!e.parent.nextSibling.children.length||e.parent.nextSibling.children[0].state!=="BLOCKQUOTE"&&e.parent.nextSibling.children[0].state!=="IMPLICIT_INDENT")n+="</blockquote>\n";return n}},CITATION:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<cite>"+t(e)+"</cite>"}},HEADING_1:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h1>"+t(e)+"</h1>"}},HEADING_2:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h2>"+t(e)+"</h2>"}},HEADING_3:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h3>"+t(e)+"</h3>"}},HEADING_4:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h4>"+t(e)+"</h4>"}},HEADING_5:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h5>"+t(e)+"</h5>"}},HEADING_6:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h6>"+t(e)+"</h6>"}},AUTO_LINK:{compile:function(e,t){var n=e.token+e.text(),r=n;if(e.parent&&e.parent.state==="PAREN_DESCRIPTOR"&&!!e.parent.link)return n;e.linkDetail&&(r=t(e.linkDetail));var i='<a href="'+n+'">'+r+"</a>";return e.exitToken.match(/\s+/)&&!e.linkDetail&&(i+=" "),i}},PAREN_DESCRIPTOR:{process:function(e){e.previousSibling&&e.previousSibling.state==="AUTO_LINK"&&(e.previousSibling.linkDetail||(e.previousSibling.linkDetail=e,e.link=e.previousSibling))},compile:function(e,t){return e.link?"":"("+t(e)+")"}},HORIZONTAL_RULE:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<hr />"}},SPECIAL_FEATHER:{process:function(e){if(!e.children.length)return-1;var t=e.children.join("").split(/\s+/ig),n=t.shift().replace(/\s+/ig,""),r={};if(!n.length)return-1;if(this.feathers[n]&&this.feathers[n]instanceof Object&&this.feathers[n].handler&&this.feathers[n].handler instanceof Function){e.children=[];var i=0,s=[],o=[];for(var u=0;u<t.length;u++){var a=t[u];i===0?a.match(/\:/)?(a=a.split(/[:]+/),s.push(a.shift()),o=o.concat(a),i=1):s.push(a):a.match(/\:/)?(i=0,u--,r[s.join(" ")]=o.join(" "),s=[],o=[]):o.push(a)}if(s.length||o.length)r[s.join(" ")]=o.join(" ");var f=this.feathers[n].handler.call(e,r,this);e.compiled=!0;if(typeof f=="string"||typeof f=="number")e.children=[f];return}return-1},compile:function(e,t){return e.children.join("")}}},typeof module!="undefined"&&module.exports?module.exports=t:typeof define!="undefined"?define("DuckdownGrammar",[],function(){return t}):e.DuckdownGrammar=t})(this),function(e){function i(e){return e.replace(n.escapeCharacters,n.replacer)}function s(e){for(var t=0;t<e.length;t++)e[t]instanceof r&&(e[t].index=t)}var n=t("./grammar.js"),r=function(e){this.index=0,this.state=e&&typeof e=="string"?e:"NODE_TEXT",this.stateStack=[],this.depth=0,this.children=[],this.parent=null,this.wrapper=!0,this.token="",this.exitToken="",this.previousSibling=null,this.nextSibling=null,this.semanticLevel="text",this.parser=null,this.processed=!1,this.blockParent=!1,this.blockType=null,this.prevSiblingCulled=!1,this.prevCulledSiblingState=null,this.nextSiblingCulled=!1,this.nextCulledSiblingState=null,this.textCache="",this.rawCache="",this.mismatched=!1};r.prototype.text=function(){var e="";if(!this.textCache.length){for(var t=0;t<this.children.length;t++)if(this.children[t]instanceof r)e+=this.children[t].text();else{if(typeof this.children[t]!="string"&&typeof this.children[t]!="number")throw new Error("Unable to coerce unsupported type to string!");var n=i(String(this.children[t]));e+=n}return this.textCache=e,this.textCache}return this.textCache},r.prototype.raw=function(e){var t="";if(!this.rawCache.length){t+=this.token;for(var s=0;s<this.children.length;s++)if(this.children[s]instanceof r)t+=this.children[s].raw();else{if(typeof this.children[s]!="string"&&typeof this.children[s]!="number")throw new Error("Unable to coerce unsupported type to string!");t+=String(this.children[s])}return n.tokenMappings[this.token].swallowWhitespace||(t+=this.exitToken),this.rawCache=t,e?i(this.rawCache):this.rawCache}return e?i(this.rawCache):this.rawCache},r.prototype.remove=function(){var e=this,t=this.parent?this.parent.children:this.parser.parserAST,n=t.filter(function(t){return t!==e});s(n),this.previousSibling&&(this.previousSibling.nextSibling=this.nextSibling),this.nextSibling&&(this.nextSibling.previousSibling=this.previousSibling),this.parent?this.parent.children=n:this.parser.parserAST=n},r.prototype.removeChild=function(e){this.updateIndices();if(!this.children[e])throw new Error("Child at index "+e+" does not exist.");this.children[e]instanceof r?this.children[e].remove():(e<this.children.length&&this.children[e+1]instanceof r&&(this.children[e+1].previousSibling=this.children[e-1]||null),e>0&&this.children[e-1]instanceof r&&(this.children[e-1].nextSibling=this.children[e+1]||null),this.children.splice(e,1),this.updateIndices())},r.prototype.updateIndices=function(){s(this.children)},r.prototype.toString=function(){return"<"+this.state+":"+this.children.length+">"},typeof module!="undefined"&&module.exports?module.exports=r:typeof define!="undefined"?define("DuckdownNode",[],function(){return r}):e.DuckdownNode=r}(this),function(e){"use strict";function a(e){if(!n.stateList[e])return!1;if(!n.stateList[e].tokenGenus){for(var t in n.tokenMappings)if(n.tokenMappings.hasOwnProperty(t)&&n.tokenMappings[t].state===e)return n.stateList[e].tokenGenus=n.tokenMappings[t],n.tokenMappings[t];return!1}return n.stateList[e].tokenGenus}var n=t("./grammar.js"),r=t("./ducknode.js"),i=0,s=1,o=0,u=function(t){this.options=t instanceof Object?t:{},this.clear()};u.prototype.clear=function(){this.currentToken="",this.prevToken="",this.tokenPosition=0,this.parserStates=[],this.parserAST=[],this.parseBuffer=[],this.currentNode=null,this.prevNode=null,this.nodeDepth=0,this.whitespace=!1,this.prevNodeCulled=!1,this.prevCullState=null,this.characterIndex=0,this.tokeniserState=i,this.tokenBuffer="",this.tokens=[],this.curChar="",this.prevChar="",this.feathers={},this.tokenList=function(){var e=[];for(var t in n.tokenMappings)n.tokenMappings.hasOwnProperty(t)&&e.push(t);return e}(),this.longestToken=this.tokenList.sort(function(e,t){return t.length-e.length}).slice(0,1).pop().length,this.emit("clear")},u.prototype.tokenise=function(e){typeof e!="string"&&(e=String(e)),this.emit("tokenisestart"),this.tokens.length||(e="\n"+e);var t=!e||!e.length?0:e.length;this.prevChar="",this.curChar="";for(var r=0;r<=t;r++){this.curChar=e.charAt(r);var o=this.longestToken;o=o>t-r?t-r:o;for(;o>0;o--){var u=e.substr(r,o);if(n.tokenMappings[u]){this.tokenBuffer.length&&(this.tokens.push(this.tokenBuffer),this.tokenBuffer=""),this.tokens.push(u),r+=o-1;break}o===1&&(!this.curChar.match(n.wordCharacters)&&this.tokeniserState===s||this.curChar.match(n.wordCharacters)&&this.tokeniserState===i?this.tokenBuffer+=this.curChar:(this.tokenBuffer.length&&(this.tokens.push(this.tokenBuffer),this.tokenBuffer=""),this.tokenBuffer+=this.curChar,this.tokeniserState=[s,i][this.tokeniserState]))}this.characterIndex=r,this.prevChar=this.curChar}return this.tokenBuffer.length&&(this.tokens.push(this.tokenBuffer),this.tokenBuffer=""),this.emit("tokeniseend",this.tokens),this.tokens},u.prototype.parse=function(e,t){e&&typeof e=="string"&&this.tokenise(e),this.emit("parsestart");for(;this.tokenPosition<this.tokens.length;this.tokenPosition++)this.parseToken(this,null);return t||this.completeParse(),this.parserAST},u.prototype.completeParse=function(){if(this.parserAST.length)while(this.parserAST[this.parserAST.length-1]&&!this.parserAST[this.parserAST.length-1].processed){var e=this.parserStates[this.parserStates.length-1],t=n.stateList[e];this.closeCurrentNode(e,t,!0)}this.emit("parseend")},u.prototype.parseToken=function(e,t){function c(){if(!e.parserStates.length)return!0;var t=e.parserStates[e.parserStates.length-1],n=a(t);return n?n.wrapper:!1}function h(t){if(!e.currentNode)return!0;if(!t.semanticLevel)return!0;if(t.semanticLevel==="hybrid")return!0;var n="hybrid",r={hybrid:4,block:3,textblock:2,text:1};for(var i=0;i<e.parserStates.length;i++){var s=a(e.parserStates[i]);s.semanticLevel&&r[s.semanticLevel]<r[n]&&(n=s.semanticLevel)}return r[t.semanticLevel]>r[n]?!1:t.semanticLevel==="textblock"&&n==="textblock"?!1:!0}function p(){var t=e.parseBuffer.filter(function(e){return!!e.replace(/\s+/ig,"").length});if(t.length)return t.pop();l=e.currentNode?e.currentNode.children:e.parserAST;if(l.length)return l[l.length-1]}var i,s,o,f,l;this instanceof u&&(e=this),t&&t.length&&(e.tokens.push(t),e.tokenPosition=e.tokens.length-1),e.currentToken=e.tokens[e.tokenPosition],e.emit("parsetoken",e.currentToken);for(var d=e.parserStates.length-1;d>=0;d--){i=e.parserStates[d],f=n.stateList[i];var v=a(i);v&&(f.exitCondition=v.exit);if(!f)throw new Error("State genus for the state "+i+" was not found! ("+e.parserStates.join(",")+")");if(f.exitCondition&&f.exitCondition.exec(e.currentToken)){while(i!==e.currentNode.state)e.currentNode.mismatched=!0,e.closeCurrentNode(!0);e.closeCurrentNode()}}if(n.tokenMappings[e.currentToken]&&n.tokenMappings.hasOwnProperty(e.currentToken)){o=n.tokenMappings[e.currentToken],s=o.state,f=n.stateList[o.state];if(e.hasParseState(o.state)&&!o.allowSelfNesting)e.parseBuffer.push(e.currentToken);else{var m=p();if(c()&&h(o)&&(!o.blankPrevSibling||typeof m!="string"||!m.match(/\S$/i))){e.addParseState(o.state);var g=new r(o.state);g.stateStack=e.parserStates.slice(0),g.depth=e.nodeDepth,g.parent=e.currentNode,g.wrapper=o.wrapper,g.token=e.currentToken,g.parser=e,g.prevSiblingCulled=e.prevNodeCulled,g.prevCulledSiblingState=e.prevCullState,o.semanticLevel&&(g.semanticLevel=o.semanticLevel),m&&(g.previousSibling=m),g.previousSibling&&g.previousSibling instanceof r&&(g.previousSibling.nextSibling=g),e.currentNode?(e.currentNode.children.push.apply(e.currentNode.children,e.parseBuffer),e.currentNode.children.push(g)):(e.parserAST.push.apply(e.parserAST,e.parseBuffer),e.parserAST.push(g)),g.index=(e.currentNode?e.currentNode.children.length:e.parserAST.length)-1;if(o.semanticLevel==="block"||o.semanticLevel==="textblock"||o.state==="IMPLICIT_INDENT"){var y=e.currentNode;while(y!==null)y.blockParent=!0,y.blockType=o.state,y.parent||(y.blockNode=g,g.rootBlock=y),y=y.parent}e.parseBuffer=[],e.currentNode=g,e.prevNodeCulled=!1,e.prevCullState=null,e.nodeDepth++}else e.parseBuffer.push(e.currentToken)}}else e.currentToken&&e.currentToken.length&&e.parseBuffer.push(e.currentToken),e.tokenPosition>=e.tokens.length-1&&(e.currentNode?e.currentNode.children.push.apply(e.currentNode.children,e.parseBuffer):e.parserAST.push.apply(e.parserAST,e.parseBuffer),e.parseBuffer=[]);return e.currentToken&&e.currentToken.match(/\s+$/)?e.whitespace=!0:e.whitespace=!1,e.previousToken=e.currentToken,e.parserStates.join(" ").toLowerCase().replace(/\_/ig,"-")},u.prototype.compile=function(e){var t=this;e&&this.parse(e),this.emit("compilestart");var i=function s(e){var i=[];i=e;var o="";e instanceof r&&(i=e.children);if(i instanceof Array){for(var u=0;u<i.length;u++){var a=i[u];if(a instanceof r){if(a.children.length&&a.text().length){var f=n.stateList[a.state];f&&f.compile&&f.compile instanceof Function?o+=f.compile.call(t,a,s):o+=s(a)}}else if(typeof a=="number"||typeof a=="string"){var l=a;n.replacer&&n.replacer instanceof Function&&(l=l.replace(n.escapeCharacters,n.replacer)),l=l.replace(/\s+/," "),o+=l}}return o.replace(/\s+/g,"").length?(e instanceof r&&(e.semanticLevel==="block"||e.semanticLevel==="textblock"||e.semanticLevel==="hybrid")&&(o=o.replace(/^\s+/,"").replace(/\s+$/,"")),o):""}return o}(this.parserAST);return this.emit("compileend",i),i},u.prototype.closeCurrentNode=function(e){var t=this.parserStates[this.parserStates.length-1],r=n.stateList[t],i=this,s={},o=null;s=a(t);var u=null,f=!1,l,c=0,h=0;i.prevNodeCulled=!1,i.prevCullState=null,e||(l=r.exitCondition.exec(i.currentToken),c=l.index,h=l[0]?l[0].length:0,c>0&&i.parseBuffer.push(i.currentToken.substr(0,c)),i.currentNode.exitToken=l[0]),i.currentNode.children.push.apply(i.currentNode.children,i.parseBuffer),s&&s.validIf instanceof RegExp&&(s.validIf.exec(i.currentNode.raw())||(i.emit("nodeinvalid",i.currentNode,s.validIf,i.currentNode.raw()),i.currentNode.rootBlock&&(i.currentNode.rootBlock.blockParent=!1,i.currentNode.rootBlock.blockType=null,i.currentNode.rootBlock.blockNode=null),f=!0)),!f&&r.process&&r.process instanceof Function&&(u=r.process.call(i,i.currentNode),u===!1&&(i.emit("nodeselfdestruct",i.currentNode),i.currentNode.culled=!0,i.prevNodeCulled=!0,i.prevCullState=i.currentNode.blockType||i.currentNode.state,i.currentNode.previousSibling&&(i.currentNode.previousSibling.nextSiblingCulled=!0,i.currentNode.previousSibling.nextCulledSiblingState=i.currentNode.state,i.currentNode.previousSibling.nextSibling=null),i.currentNode.rootBlock&&(i.currentNode.rootBlock.blockParent=!1,i.currentNode.rootBlock.blockType=null,i.currentNode.rootBlock.blockNode=null)),u===-1&&(i.emit("nodeinvalid",i.currentNode),i.currentNode.rootBlock&&(i.currentNode.rootBlock.blockParent=!1,i.currentNode.rootBlock.blockType=null,i.currentNode.rootBlock.blockNode=null),f=!0)),i.currentNode.processed=!0;if(u===!1||f)o=i.currentNode.parent?i.currentNode.parent.children:i.parserAST,o.length--,f&&o.push.apply(o,[i.currentNode.token].concat(i.currentNode.children));i.parseBuffer=[],i.emit("nodeclosed",i.currentNode),!f&&u!==!1&&(i.prevNode=i.currentNode),i.currentNode=i.currentNode.parent,i.nodeDepth--,i.parserStates.length=i.nodeDepth;if(!e)if((r.tokenGenus.swallowTokens!==!1&&!f||!!r.tokenGenus.swallowWhitespace&&l[0].match(/\s+/ig)&&!f)&&i.currentToken!=="\n"){i.currentToken=i.currentToken.substring(c+h);if(!i.currentToken.length)return}else c>0&&(i.currentToken=i.currentToken.substring(c))},u.prototype.toString=function(){return this.compile()},u.prototype.registerFeather=function(e,t,n){var r={text:1,textblock:1,block:1,hybrid:1};n=n?n:"block";if(!e.match(/^[a-z0-9]+$/))throw new Error("Feather names must consist of lowercase letters and numbers only.");if(this.feathers[e])throw new Error("A feather with the specified name already exists.");if(!(t&&t instanceof Function))throw new Error("You must provide a function for processing the feather output.");if(!(n in r))throw new Error("Feather semantic level must be one of (text|textblock|block|hybrid)");this.emit("registerfeather",e,t),this.feathers[e]={handler:t,semanticLevel:n}},u.prototype.unregisterFeather=function(e){if(!this.feathers[e])throw new Error("Requested feather does not exist.");this.emit("unregisterfeather",e),delete this.feathers[e]},u.prototype.hasParseState=function(e){for(var t=0;t<this.parserStates.length;t++)if(this.parserStates[t]===e)return!0;return!1},u.prototype.addParseState=function(e){this.emit("addstate",e),this.parserStates.push(e)},u.prototype.emit=function(e){var t=this,n=arguments;if(!this.eventListeners)return;if(!this.eventListeners[e]||!(this.eventListeners[e]instanceof Array))return;this.eventListeners[e].filter(function(e){return e instanceof Function}).forEach(function(e){e.apply(t,[].slice.call(n,1))})},u.prototype.on=function(e,t){if(!e||typeof e!="string"||e.match(/[^a-z0-9\.\*\-]/ig))throw new Error("Attempted to subscribe to event with invalid name!");if(!t||!(t instanceof Function))throw new Error("Attempted to subscribe to event without a listener function!");if(!this.eventListeners||!(this.eventListeners instanceof Object))this.eventListeners={};this.eventListeners[e]&&this.eventListeners[e]instanceof Array?this.eventListeners[e].push(t):this.eventListeners[e]=[t]},typeof module!="undefined"&&module.exports?module.exports=u:typeof define!="undefined"?define("Duckdown",[],function(){return u}):e.Duckdown=u}(this)})(this)
+(function(e){function t(e){return window[{"./ducknode.js":"DuckdownNode","./duckdown.js":"Duckdown","./grammar.js":"DuckdownGrammar","../grammar":"DuckdownGrammar"}[e]]}(function(e){"use strict";var t={};t.wordCharacters=/[a-z0-9 ]/ig,t.escapeCharacters=/[^a-z0-9\s\-\_\:\\\/\=\%\~\`\!\@\#\$\*\(\)\+\[\]\{\}\|\;\,\.\?\']/ig,t.replacer=function(e,t,n){return e==="&"?"&amp;":e==="<"?"&lt;":e===">"?"&gt;":e==='"'?"&quot;":"&#x"+e.charCodeAt(0).toString(16)+";"},t.tokenMappings={"\n":{wrapper:!0,swallowTokens:!1,exit:/\n/,state:"IMPLICIT_BREAK",semanticLevel:"hybrid"}," ":{wrapper:!0,swallowTokens:!1,exit:/\n/,state:"IMPLICIT_INDENT",semanticLevel:"hybrid",allowSelfNesting:!0}," ":{wrapper:!0,swallowTokens:!1,exit:/\n/,state:"IMPLICIT_INDENT",semanticLevel:"hybrid",allowSelfNesting:!0},"&":{wrapper:!1,exit:/([^#a-z0-9]|;)/i,validIf:/^&#?[a-z0-9]+;$/ig,state:"ENTITY",semanticLevel:"text"},"~":{semanticLevel:"text",wrapper:!0,allowSelfNesting:!1,exit:/[\~\n]/,validIf:/^\~\S[^\n]+\S\~$/,state:"TEXT_EMPHASIS"},"*":{semanticLevel:"text",wrapper:!0,allowSelfNesting:!1,exit:/[\*\n]/,validIf:/^\*\S[^\n]+\S\*$/,state:"TEXT_STRONG"},"-":{state:"TEXT_DEL",wrapper:!0,semanticLevel:"text",exit:/[\-\n]/,validIf:/^\-\S[^\n]+\S\-$/,blankPrevSibling:!0},_:{wrapper:!0,semanticLevel:"text",exit:/[_\n]/,validIf:/^\_\S[^\n]+\S\_$/,state:"TEXT_UNDERLINE"},"<":{wrapper:!1,semanticLevel:"hybrid",exit:/[>\n]/,validIf:/^<[a-z][a-z0-9\-\_]*(\s[^>\n]+)*>$/i,state:"SPECIAL_FEATHER"},"`":{wrapper:!1,semanticLevel:"text",exit:/[`\n]/,state:"CODE_LITERAL"},'"':{wrapper:!1,semanticLevel:"text",exit:/["\n]/,validIf:/^\".*\"$/,state:"TEXT_QUOTE"},"* ":{wrapper:!0,exit:/\n/i,state:"LIST_UNORDERED",semanticLevel:"textblock",swallowTokens:!1},"* ":{wrapper:!0,exit:/\n/i,state:"LIST_UNORDERED",semanticLevel:"textblock",swallowTokens:!1},". ":{wrapper:!0,exit:/\n/i,state:"LIST_ORDERED",semanticLevel:"textblock",swallowTokens:!1},". ":{wrapper:!0,exit:/\n/i,state:"LIST_ORDERED",semanticLevel:"textblock",swallowTokens:!1},">":{wrapper:!0,exit:/\n/i,state:"BLOCKQUOTE",semanticLevel:"block",allowSelfNesting:"true",swallowTokens:!1,mustBeFirstChild:!0},"h1.":{wrapper:!0,exit:/\n/i,state:"HEADING_1",semanticLevel:"textblock"},"h2.":{wrapper:!0,exit:/\n/i,state:"HEADING_2",semanticLevel:"textblock"},"h3.":{wrapper:!0,exit:/\n/i,state:"HEADING_3",semanticLevel:"textblock"},"h4.":{wrapper:!0,exit:/\n/i,state:"HEADING_4",semanticLevel:"textblock"},"h5.":{wrapper:!0,exit:/\n/i,state:"HEADING_5",semanticLevel:"textblock"},"h6.":{wrapper:!0,exit:/\n/i,state:"HEADING_6",semanticLevel:"textblock"},"http://":{state:"AUTO_LINK",wrapper:!1,exit:/[^a-z0-9\-_\.\~\!\*\'\(\)\;\:\@\&\=\+\$\,\/\?\%\#\[\]\#]/i,validIf:/^http[s]?:\/\/[a-z0-9\-\.]+(\:\d+)?.*$/i,swallowTokens:!1,swallowWhitespace:!0,semanticLevel:"text"},"https://":{state:"AUTO_LINK",wrapper:!1,exit:/[^a-z0-9\-_\.\~\!\*\'\(\)\;\:\@\&\=\+\$\,\/\?\%\#\[\]\#]/i,validIf:/^http[s]?:\/\/[a-z0-9\-\.]+(\:\d+)?.*$/i,swallowTokens:!1,swallowWhitespace:!0,semanticLevel:"text"},"(":{state:"PAREN_DESCRIPTOR",wrapper:!0,exit:/(\s\s+|\n|\))/,validIf:/^\([^\n]+\)$/,allowSelfNesting:!0,semanticLevel:"text"},"-- ":{state:"CITATION",exit:/\n/,wrapper:!0,semanticLevel:"text",swallowTokens:!1},"--":{state:"HORIZONTAL_RULE",wrapper:!1,exit:/[^\-]/i,validIf:/^\-\-+\n*$/i,semanticLevel:"block",swallowTokens:!1}},t.stateList={ENTITY:{process:function(){},compile:function(e,t){var n=e.children[e.children.length-1];return e.exitToken===";"?"&"+e.children.join("")+";":typeof n=="string"&&n.match(/\;/)?"&"+e.children.join(""):"&amp;"+t(e)}},IMPLICIT_BREAK:{process:function(e){if(!e.text().length&&!e.blockParent)return!1;for(var t=0;t<e.children.length;t++)if(e.children[t].state==="IMPLICIT_INDENT"){e.blockParent=!0;break}},compile:function(e,t){var n=t(e),r=!e.blockParent;if(r){var i=!1,s=!1;if(!e.previousSibling||e.prevSiblingCulled&&e.prevCulledSiblingState==="IMPLICIT_BREAK"||e.previousSibling.blockParent)i=!0;if(!e.nextSibling||e.nextSiblingCulled&&e.nextCulledSiblingState==="IMPLICIT_BREAK")s=!0;e.nextSibling&&(e.nextSibling.blockParent||!e.nextSibling.children.length)&&(s=!0);var o=n.match(/\s+$/i)?"":" ";return i&&(n="<p>"+n),n+=s?"</p>\n":o,n}return n+"\n"}},IMPLICIT_INDENT:{process:function(e){if(!e.text().length)return!1},compile:function(e,t){var n=!1;if(!e.parent||e.previousSibling||e.parent.state==="IMPLICIT_BREAK"||e.parent.semanticLevel==="block"||e.parent.semanticLevel==="hybrid")e.parent?!e.parent.previousSibling&&!e.previousSibling&&e.parent.state!=="IMPLICIT_INDENT"?n=!0:e.parent.prevSiblingCulled&&e.parent.prevCulledSiblingState==="IMPLICIT_BREAK"&&(n=!0):n=!0;return n?"<pre>"+e.raw(!0).replace(/^\s+/,"")+"</pre>\n":t(e)}},TEXT_EMPHASIS:{compile:function(e,t){return"<em>"+t(e)+"</em>"}},TEXT_STRONG:{compile:function(e,t){return"<strong>"+t(e)+"</strong>"}},TEXT_DEL:{process:function(e){return e.previousSibling?typeof e.previousSibling=="string"&&e.previousSibling.match(/\s$/g)?!0:typeof e.previousSibling=="object"?!0:-1:!0},compile:function(e,t){return"<del>"+t(e)+"</del>"}},TEXT_QUOTE:{process:function(e){if(e.parent&&!e.parent.prevSiblingCulled&&e.parent.previousSibling&&e.parent.previousSibling.state===e.parent.state)return-1},compile:function(e,t){return"<q>"+t(e)+"</q>"}},TEXT_UNDERLINE:{compile:function(e,t){return"<u>"+t(e)+"</u>"}},CODE_LITERAL:{compile:function(e,t){return"<code>"+e.text()+"</code>"}},LIST_UNORDERED:{process:function(e){if(e.previousSibling)return-1;if(!e.parent)return-1;if(e.parent.previousSibling&&typeof e.parent.previousSibling=="object"&&e.parent.previousSibling.state!==e.parent.state&&!e.parent.prevSiblingCulled)return-1;if(e.rootBlock&&e.rootBlock.previousSibling&&!e.rootBlock.prevSiblingCulled&&e.rootBlock.previousSibling.blockType!==e.state&&e.rootBlock.previousSibling.blockType!=="LIST_ORDERED")return-1;var t=e,n=0;while(t)t.state==="IMPLICIT_INDENT"&&n++,t=t.parent;e.indentation=n;if(e.rootBlock&&e.rootBlock.previousSibling&&e.rootBlock.previousSibling.blockNode&&(e.rootBlock.previousSibling.semanticLevel==="hybrid"||e.rootBlock.previousSibling.semanticLevel==="textblock"||e.rootBlock.previousSibling.semanticLevel==="block")&&e.rootBlock.previousSibling.blockNode.indentation<e.indentation){var r=e.rootBlock.previousSibling.blockNode;while(r.children.length&&typeof r.children[r.children.length-1]=="object"&&(r.children[r.children.length-1].semanticLevel==="hybrid"||r.children[r.children.length-1].semanticLevel==="textblock"||r.children[r.children.length-1].semanticLevel==="block")){if(r.children[r.children.length-1].indentation!==null&&r.children[r.children.length-1].indentation>=e.indentation)break;r=r.children[r.children.length-1]}r.children.push(e),r.blockParent=!0,e.rootBlock.remove(),r.updateIndices(),r.children[e.index-1]&&(typeof r.children[e.index-1]!="object"||r.children[e.index-1].state!==e.state)&&(e.breakBefore=!0)}},compile:function(e,t){var n="";e.breakBefore&&(n+="\n");if(!e.parent.previousSibling||e.parent.prevSiblingCulled||!e.parent.previousSibling.blockParent||!e.parent.previousSibling.children.length||e.parent.previousSibling.children[0].state!=="LIST_UNORDERED"&&e.parent.previousSibling.children[0].state!=="IMPLICIT_INDENT")n+="<ul>\n";n+="<li>"+t(e)+"</li>\n";if(!e.parent.nextSibling||e.parent.nextSiblingCulled||!e.parent.nextSibling.blockParent||!e.parent.nextSibling.children.length||e.parent.nextSibling.children[0].state!=="LIST_UNORDERED"&&e.parent.nextSibling.children[0].state!=="IMPLICIT_INDENT")n+="</ul>\n";return n}},LIST_ORDERED:{process:function(e){if(e.previousSibling&&(typeof e.previousSibling=="object"||e.previousSibling.match(/[^a-z0-9]/g)))return-1;if(!e.parent)return-1;if(e.parent.previousSibling&&typeof e.parent.previousSibling=="object"&&e.parent.previousSibling.state!==e.parent.state&&!e.parent.prevSiblingCulled)return-1;if(e.rootBlock&&e.rootBlock.previousSibling&&!e.rootBlock.prevSiblingCulled&&e.rootBlock.previousSibling.blockType!==e.state&&e.rootBlock.previousSibling.blockType!=="LIST_UNORDERED")return-1;if(e.previousSibling&&e.previousSibling.match(/^[a-z0-9]+$/)&&e.index<2){e.listQualifier=e.previousSibling,e.parent.removeChild(e.index-1);var t=e,n=0;while(t)t.state==="IMPLICIT_INDENT"&&n++,t=t.parent;e.indentation=n;if(e.rootBlock&&e.rootBlock.previousSibling&&e.rootBlock.previousSibling.blockNode&&(e.rootBlock.previousSibling.semanticLevel==="hybrid"||e.rootBlock.previousSibling.semanticLevel==="textblock"||e.rootBlock.previousSibling.semanticLevel==="block")&&e.rootBlock.previousSibling.blockNode.indentation<e.indentation){var r=e.rootBlock.previousSibling.blockNode;while(r.children.length&&typeof r.children[r.children.length-1]=="object"&&(r.children[r.children.length-1].semanticLevel==="hybrid"||r.children[r.children.length-1].semanticLevel==="textblock"||r.children[r.children.length-1].semanticLevel==="block")){if(r.children[r.children.length-1].indentation!==null&&r.children[r.children.length-1].indentation>=e.indentation)break;r=r.children[r.children.length-1]}r.children.push(e),r.blockParent=!0,e.rootBlock.remove(),r.updateIndices(),r.children[e.index-1]&&(typeof r.children[e.index-1]!="object"||r.children[e.index-1].state!==e.state)&&(e.breakBefore=!0)}return!0}return-1},compile:function(e,t){var n="";e.breakBefore&&(n+="\n");if(!e.parent.previousSibling||e.parent.prevSiblingCulled||!e.parent.previousSibling.blockParent||!e.parent.previousSibling.children.length||e.parent.previousSibling.children[0].state!=="LIST_ORDERED"&&e.parent.previousSibling.children[0].state!=="IMPLICIT_INDENT"){var r="";e.listQualifier.match(/[ivxcmd]/ig)?r="lower-roman":e.listQualifier.match(/[a-z]/ig)&&(r="lower-alpha"),r=r.length?' style="list-style: '+r+';"':"",n+="<ol"+r+">\n"}n+="<li>"+t(e)+(e.blockParent?"\n":"")+"</li>\n";if(!e.parent.nextSibling||e.parent.nextSiblingCulled||!e.parent.nextSibling.blockParent||!e.parent.nextSibling.children.length||e.parent.nextSibling.children[0].state!=="LIST_ORDERED"&&e.parent.nextSibling.children[0].state!=="IMPLICIT_INDENT")n+="</ol>\n";return n}},BLOCKQUOTE:{process:function(e){if(e.previousSibling)return-1;var t=0,n=e,r;while(n)n.state===e.state&&t++,n=n.parent;e.indentation=t;if(e.rootBlock&&e.rootBlock.previousSibling&&(!e.rootBlock.prevSiblingCulled||e.rootBlock.prevCulledSiblingState===e.state)&&e.rootBlock.previousSibling.blockType===e.state&&e.rootBlock.previousSibling.blockNode){e.rootBlock.previousSibling.blockNode.indentation<e.indentation,n=e.rootBlock.previousSibling.blockNode;while(n&&!r)n.indentation<e.indentation&&(r=n),n=n.parent;if(r){var i=e.rootBlock,s=i.previousSibling;i.remove(),i.children=e.children,e.children=[i],s.blockNode.children.push(e)}}},compile:function(e,t){var n="";if(!e.parent.previousSibling||e.parent.prevSiblingCulled||!e.parent.previousSibling.blockParent||!e.parent.previousSibling.children.length||e.parent.previousSibling.children[0].state!=="BLOCKQUOTE"&&e.parent.previousSibling.children[0].state!=="IMPLICIT_INDENT")n+="<blockquote>\n";var r=t(e);r.length&&(e.blockParent||(n+="<p>"),n+=r,e.blockParent||(n+="</p>\n"));if(!e.parent.nextSibling||e.parent.nextSiblingCulled||!e.parent.nextSibling.blockParent||!e.parent.nextSibling.children.length||e.parent.nextSibling.children[0].state!=="BLOCKQUOTE"&&e.parent.nextSibling.children[0].state!=="IMPLICIT_INDENT")n+="</blockquote>\n";return n}},CITATION:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<cite>"+t(e)+"</cite>"}},HEADING_1:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h1>"+t(e)+"</h1>"}},HEADING_2:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h2>"+t(e)+"</h2>"}},HEADING_3:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h3>"+t(e)+"</h3>"}},HEADING_4:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h4>"+t(e)+"</h4>"}},HEADING_5:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h5>"+t(e)+"</h5>"}},HEADING_6:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<h6>"+t(e)+"</h6>"}},AUTO_LINK:{compile:function(e,t){var n=e.token+e.text(),r=n;if(e.parent&&e.parent.state==="PAREN_DESCRIPTOR"&&!!e.parent.link)return n;e.linkDetail&&(r=t(e.linkDetail));var i='<a href="'+n+'">'+r+"</a>";return e.exitToken.match(/\s+/)&&!e.linkDetail&&(i+=" "),i}},PAREN_DESCRIPTOR:{process:function(e){e.previousSibling&&e.previousSibling.state==="AUTO_LINK"&&(e.previousSibling.linkDetail||(e.previousSibling.linkDetail=e,e.link=e.previousSibling))},compile:function(e,t){return e.link?"":"("+t(e)+")"}},HORIZONTAL_RULE:{process:function(e){if(e.previousSibling)return-1},compile:function(e,t){return"<hr />"}},SPECIAL_FEATHER:{process:function(e){if(!e.children.length)return-1;var t=e.children.join("").split(/\s+/ig),n=t.shift().replace(/\s+/ig,""),r={};if(!n.length)return-1;if(this.feathers[n]&&this.feathers[n]instanceof Object&&this.feathers[n].handler&&this.feathers[n].handler instanceof Function){e.children=[];var i=0,s=[],o=[];for(var u=0;u<t.length;u++){var a=t[u];i===0?a.match(/\:/)?(a=a.split(/[:]+/),s.push(a.shift()),o=o.concat(a),i=1):s.push(a):a.match(/\:/)?(i=0,u--,r[s.join(" ")]=o.join(" "),s=[],o=[]):o.push(a)}if(s.length||o.length)r[s.join(" ")]=o.join(" ");var f=this.feathers[n].handler.call(e,r,this);e.compiled=!0;if(typeof f=="string"||typeof f=="number")e.children=[f];return}return-1},compile:function(e,t){return e.children.join("")}}},typeof module!="undefined"&&module.exports?module.exports=t:typeof define!="undefined"?define("DuckdownGrammar",[],function(){return t}):e.DuckdownGrammar=t})(this),function(e){function i(e){return e.replace(n.escapeCharacters,n.replacer)}function s(e){for(var t=0;t<e.length;t++)e[t]instanceof r&&(e[t].index=t)}var n=t("./grammar.js"),r=function(e){this.index=0,this.state=e&&typeof e=="string"?e:"NODE_TEXT",this.stateStack=[],this.depth=0,this.children=[],this.parent=null,this.wrapper=!0,this.token="",this.exitToken="",this.previousSibling=null,this.nextSibling=null,this.semanticLevel="text",this.parser=null,this.processed=!1,this.blockParent=!1,this.blockType=null,this.prevSiblingCulled=!1,this.prevCulledSiblingState=null,this.nextSiblingCulled=!1,this.nextCulledSiblingState=null,this.textCache="",this.rawCache="",this.mismatched=!1};r.prototype.text=function(){var e="";if(!this.textCache.length){for(var t=0;t<this.children.length;t++)if(this.children[t]instanceof r)e+=this.children[t].text();else{if(typeof this.children[t]!="string"&&typeof this.children[t]!="number")throw new Error("Unable to coerce unsupported type to string!");var n=i(String(this.children[t]));e+=n}return this.textCache=e,this.textCache}return this.textCache},r.prototype.raw=function(e){var t="";if(!this.rawCache.length){t+=this.token;for(var s=0;s<this.children.length;s++)if(this.children[s]instanceof r)t+=this.children[s].raw();else{if(typeof this.children[s]!="string"&&typeof this.children[s]!="number")throw new Error("Unable to coerce unsupported type to string!");t+=String(this.children[s])}return n.tokenMappings[this.token].swallowWhitespace||(t+=this.exitToken),this.rawCache=t,e?i(this.rawCache):this.rawCache}return e?i(this.rawCache):this.rawCache},r.prototype.remove=function(){var e=this,t=this.parent?this.parent.children:this.parser.parserAST,n=t.filter(function(t){return t!==e});s(n),this.previousSibling&&(this.previousSibling.nextSibling=this.nextSibling),this.nextSibling&&(this.nextSibling.previousSibling=this.previousSibling),this.parent?this.parent.children=n:this.parser.parserAST=n},r.prototype.removeChild=function(e){this.updateIndices();if(!this.children[e])throw new Error("Child at index "+e+" does not exist.");this.children[e]instanceof r?this.children[e].remove():(e<this.children.length&&this.children[e+1]instanceof r&&(this.children[e+1].previousSibling=this.children[e-1]||null),e>0&&this.children[e-1]instanceof r&&(this.children[e-1].nextSibling=this.children[e+1]||null),this.children.splice(e,1),this.updateIndices())},r.prototype.updateIndices=function(){s(this.children)},r.prototype.toString=function(){return"<"+this.state+":"+this.children.length+">"},typeof module!="undefined"&&module.exports?module.exports=r:typeof define!="undefined"?define("DuckdownNode",[],function(){return r}):e.DuckdownNode=r}(this),function(e){"use strict";function a(e){if(!n.stateList[e])return!1;if(!n.stateList[e].tokenGenus){for(var t in n.tokenMappings)if(n.tokenMappings.hasOwnProperty(t)&&n.tokenMappings[t].state===e)return n.stateList[e].tokenGenus=n.tokenMappings[t],n.tokenMappings[t];return!1}return n.stateList[e].tokenGenus}var n=t("./grammar.js"),r=t("./ducknode.js"),i=0,s=1,o=0,u=function(t){this.options=t instanceof Object?t:{},this.clear()};u.prototype.clear=function(){this.currentToken="",this.prevToken="",this.tokenPosition=0,this.parserStates=[],this.parserAST=[],this.parseBuffer=[],this.currentNode=null,this.prevNode=null,this.nodeDepth=0,this.whitespace=!1,this.prevNodeCulled=!1,this.prevCullState=null,this.characterIndex=0,this.tokeniserState=i,this.tokenBuffer="",this.tokens=[],this.curChar="",this.prevChar="",this.feathers={},this.tokenList=function(){var e=[];for(var t in n.tokenMappings)n.tokenMappings.hasOwnProperty(t)&&e.push(t);return e}(),this.longestToken=this.tokenList.sort(function(e,t){return t.length-e.length}).slice(0,1).pop().length,this.emit("clear")},u.prototype.tokenise=function(e){typeof e!="string"&&(e=String(e)),this.emit("tokenisestart"),this.tokens.length||(e="\n"+e);var t=!e||!e.length?0:e.length;this.prevChar="",this.curChar="";for(var r=0;r<=t;r++){this.curChar=e.charAt(r);var o=this.longestToken;o=o>t-r?t-r:o;for(;o>0;o--){var u=e.substr(r,o);if(n.tokenMappings[u]){this.tokenBuffer.length&&(this.tokens.push(this.tokenBuffer),this.tokenBuffer=""),this.tokens.push(u),r+=o-1;break}o===1&&(!this.curChar.match(n.wordCharacters)&&this.tokeniserState===s||this.curChar.match(n.wordCharacters)&&this.tokeniserState===i?this.tokenBuffer+=this.curChar:(this.tokenBuffer.length&&(this.tokens.push(this.tokenBuffer),this.tokenBuffer=""),this.tokenBuffer+=this.curChar,this.tokeniserState=[s,i][this.tokeniserState]))}this.characterIndex=r,this.prevChar=this.curChar}return this.tokenBuffer.length&&(this.tokens.push(this.tokenBuffer),this.tokenBuffer=""),this.emit("tokeniseend",this.tokens),this.tokens},u.prototype.parse=function(e,t){e&&typeof e=="string"&&this.tokenise(e),this.emit("parsestart");for(;this.tokenPosition<this.tokens.length;this.tokenPosition++)this.parseToken(this,null);return t||this.completeParse(),this.parserAST},u.prototype.completeParse=function(){if(this.parserAST.length)while(this.parserAST[this.parserAST.length-1]&&!this.parserAST[this.parserAST.length-1].processed){var e=this.parserStates[this.parserStates.length-1],t=n.stateList[e];this.closeCurrentNode(e,t,!0)}this.emit("parseend")},u.prototype.parseToken=function(e,t){function p(){if(!e.parserStates.length)return!0;var t=e.parserStates[e.parserStates.length-1],n=a(t);return n?n.wrapper:!1}function d(t){if(!e.currentNode)return!0;if(!t.semanticLevel)return!0;if(t.semanticLevel==="hybrid")return!0;var n="hybrid",r={hybrid:4,block:3,textblock:2,text:1};for(var i=0;i<e.parserStates.length;i++){var s=a(e.parserStates[i]);s.semanticLevel&&r[s.semanticLevel]<r[n]&&(n=s.semanticLevel)}return r[t.semanticLevel]>r[n]?!1:t.semanticLevel==="textblock"&&n==="textblock"?!1:!0}function v(){var t=e.parseBuffer.filter(function(e){return!!e.replace(/\s+/ig,"").length});if(t.length)return t.pop();l=e.currentNode?e.currentNode.children:e.parserAST;if(l.length)return l[l.length-1]}var i,s,o,f,l,c=[],h;this instanceof u&&(e=this),t&&t.length&&(e.tokens.push(t),e.tokenPosition=e.tokens.length-1),e.currentToken=e.tokens[e.tokenPosition],e.emit("parsetoken",e.currentToken);for(var m=e.parserStates.length-1;m>=0;m--){i=e.parserStates[m],f=n.stateList[i];var g=a(i);g&&(f.exitCondition=g.exit);if(!f)throw new Error("State genus for the state "+i+" was not found! ("+e.parserStates.join(",")+")");if(f.exitCondition&&f.exitCondition.exec(e.currentToken)){while(i!==e.currentNode.state)e.currentNode.mismatched=!0,h=e.closeCurrentNode(!0),h&&h.length&&(c=c.concat(h));h=e.closeCurrentNode(),h&&h.length&&(c=c.concat(h))}}if(n.tokenMappings[e.currentToken]&&n.tokenMappings.hasOwnProperty(e.currentToken)){o=n.tokenMappings[e.currentToken],s=o.state,f=n.stateList[o.state];if(e.hasParseState(o.state)&&!o.allowSelfNesting)e.parseBuffer.push(e.currentToken);else{var y=v();if(p()&&d(o)&&(!o.blankPrevSibling||typeof y!="string"||!y.match(/\S$/i))){e.addParseState(o.state);var b=new r(o.state);b.stateStack=e.parserStates.slice(0),b.depth=e.nodeDepth,b.parent=e.currentNode,b.wrapper=o.wrapper,b.token=e.currentToken,b.parser=e,b.prevSiblingCulled=e.prevNodeCulled,b.prevCulledSiblingState=e.prevCullState,o.semanticLevel&&(b.semanticLevel=o.semanticLevel),y&&(b.previousSibling=y),b.previousSibling&&b.previousSibling instanceof r&&(b.previousSibling.nextSibling=b),e.currentNode?(e.currentNode.children.push.apply(e.currentNode.children,e.parseBuffer),e.currentNode.children.push(b)):(e.parserAST.push.apply(e.parserAST,e.parseBuffer),e.parserAST.push(b)),b.index=(e.currentNode?e.currentNode.children.length:e.parserAST.length)-1;if(o.semanticLevel==="block"||o.semanticLevel==="textblock"||o.state==="IMPLICIT_INDENT"){var w=e.currentNode;while(w!==null)w.blockParent=!0,w.blockType=o.state,w.parent||(w.blockNode=b,b.rootBlock=w),w=w.parent}e.parseBuffer=[],e.currentNode=b,e.prevNodeCulled=!1,e.prevCullState=null,e.nodeDepth++}else e.parseBuffer.push(e.currentToken)}}else e.currentToken&&e.currentToken.length&&e.parseBuffer.push(e.currentToken),e.tokenPosition>=e.tokens.length-1&&(e.currentNode?e.currentNode.children.push.apply(e.currentNode.children,e.parseBuffer):e.parserAST.push.apply(e.parserAST,e.parseBuffer),e.parseBuffer=[]);return e.currentToken&&e.currentToken.match(/\s+$/)?e.whitespace=!0:e.whitespace=!1,e.previousToken=e.currentToken,e.parserStates.concat(c).join(" ").toLowerCase().replace(/\_/ig,"-")},u.prototype.compile=function(e){var t=this;e&&this.parse(e),this.emit("compilestart");var i=function s(e){var i=[];i=e;var o="";e instanceof r&&(i=e.children);if(i instanceof Array){for(var u=0;u<i.length;u++){var a=i[u];if(a instanceof r){if(a.children.length&&a.text().length){var f=n.stateList[a.state];f&&f.compile&&f.compile instanceof Function?o+=f.compile.call(t,a,s):o+=s(a)}}else if(typeof a=="number"||typeof a=="string"){var l=a;n.replacer&&n.replacer instanceof Function&&(l=l.replace(n.escapeCharacters,n.replacer)),l=l.replace(/\s+/," "),o+=l}}return o.replace(/\s+/g,"").length?(e instanceof r&&(e.semanticLevel==="block"||e.semanticLevel==="textblock"||e.semanticLevel==="hybrid")&&(o=o.replace(/^\s+/,"").replace(/\s+$/,"")),o):""}return o}(this.parserAST);return this.emit("compileend",i),i},u.prototype.closeCurrentNode=function(e){var t=this.parserStates[this.parserStates.length-1],r=n.stateList[t],i=[],s=this,o={},u=null;o=a(t);var f=null,l=!1,c,h=0,p=0;s.prevNodeCulled=!1,s.prevCullState=null,e||(c=r.exitCondition.exec(s.currentToken),h=c.index,p=c[0]?c[0].length:0,h>0&&s.parseBuffer.push(s.currentToken.substr(0,h)),s.currentNode.exitToken=c[0]),s.currentNode.children.push.apply(s.currentNode.children,s.parseBuffer),o&&o.validIf instanceof RegExp&&(o.validIf.exec(s.currentNode.raw())||(s.emit("nodeinvalid",s.currentNode,o.validIf,s.currentNode.raw()),s.currentNode.rootBlock&&(s.currentNode.rootBlock.blockParent=!1,s.currentNode.rootBlock.blockType=null,s.currentNode.rootBlock.blockNode=null),l=!0)),!l&&r.process&&r.process instanceof Function&&(f=r.process.call(s,s.currentNode),f===!1&&(s.emit("nodeselfdestruct",s.currentNode),s.currentNode.culled=!0,s.prevNodeCulled=!0,s.prevCullState=s.currentNode.blockType||s.currentNode.state,s.currentNode.previousSibling&&(s.currentNode.previousSibling.nextSiblingCulled=!0,s.currentNode.previousSibling.nextCulledSiblingState=s.currentNode.state,s.currentNode.previousSibling.nextSibling=null),s.currentNode.rootBlock&&(s.currentNode.rootBlock.blockParent=!1,s.currentNode.rootBlock.blockType=null,s.currentNode.rootBlock.blockNode=null)),f===-1&&(s.emit("nodeinvalid",s.currentNode),s.currentNode.rootBlock&&(s.currentNode.rootBlock.blockParent=!1,s.currentNode.rootBlock.blockType=null,s.currentNode.rootBlock.blockNode=null),l=!0)),s.currentNode.processed=!0;if(f===!1||l)u=s.currentNode.parent?s.currentNode.parent.children:s.parserAST,u.length--,l&&u.push.apply(u,[s.currentNode.token].concat(s.currentNode.children));s.parseBuffer=[],s.emit("nodeclosed",s.currentNode),!l&&f!==!1&&(s.prevNode=s.currentNode),s.currentNode=s.currentNode.parent,s.nodeDepth--,s.nodeDepth<s.parserStates.length&&(i=s.parserStates.splice(s.nodeDepth-s.parserStates.length));if(!e)if((r.tokenGenus.swallowTokens!==!1&&!l||!!r.tokenGenus.swallowWhitespace&&c[0].match(/\s+/ig)&&!l)&&s.currentToken!=="\n"){s.currentToken=s.currentToken.substring(h+p);if(!s.currentToken.length)return}else h>0&&(s.currentToken=s.currentToken.substring(h));return i},u.prototype.toString=function(){return this.compile()},u.prototype.registerFeather=function(e,t,n){var r={text:1,textblock:1,block:1,hybrid:1};n=n?n:"block";if(!e.match(/^[a-z0-9]+$/))throw new Error("Feather names must consist of lowercase letters and numbers only.");if(this.feathers[e])throw new Error("A feather with the specified name already exists.");if(!(t&&t instanceof Function))throw new Error("You must provide a function for processing the feather output.");if(!(n in r))throw new Error("Feather semantic level must be one of (text|textblock|block|hybrid)");this.emit("registerfeather",e,t),this.feathers[e]={handler:t,semanticLevel:n}},u.prototype.unregisterFeather=function(e){if(!this.feathers[e])throw new Error("Requested feather does not exist.");this.emit("unregisterfeather",e),delete this.feathers[e]},u.prototype.hasParseState=function(e){for(var t=0;t<this.parserStates.length;t++)if(this.parserStates[t]===e)return!0;return!1},u.prototype.addParseState=function(e){this.emit("addstate",e),this.parserStates.push(e)},u.prototype.emit=function(e){var t=this,n=arguments;if(!this.eventListeners)return;if(!this.eventListeners[e]||!(this.eventListeners[e]instanceof Array))return;this.eventListeners[e].filter(function(e){return e instanceof Function}).forEach(function(e){e.apply(t,[].slice.call(n,1))})},u.prototype.on=function(e,t){if(!e||typeof e!="string"||e.match(/[^a-z0-9\.\*\-]/ig))throw new Error("Attempted to subscribe to event with invalid name!");if(!t||!(t instanceof Function))throw new Error("Attempted to subscribe to event without a listener function!");if(!this.eventListeners||!(this.eventListeners instanceof Object))this.eventListeners={};this.eventListeners[e]&&this.eventListeners[e]instanceof Array?this.eventListeners[e].push(t):this.eventListeners[e]=[t]},typeof module!="undefined"&&module.exports?module.exports=u:typeof define!="undefined"?define("Duckdown",[],function(){return u}):e.Duckdown=u}(this)})(this)
View
2 lib/cli.js
@@ -42,7 +42,7 @@
if (duck.build) {
console.log("Building Duckdown for the browser.");
- var build = require(__dirname + "/builder/build.js"),
+ var build = require(__dirname + "/../builder/build.js"),
buildFile = __dirname + "/../compiled/duckdown-unminified.js",
minFilename = __dirname + "/../compiled/duckdown.js";
View
23 lib/duckdown.js
@@ -232,7 +232,8 @@
};
Duckdown.prototype.parseToken = function(state, input) {
- var currentState, newState, tokenGenus, stateGenus, tree;
+ var currentState, newState, tokenGenus, stateGenus, tree,
+ closedNodeStates = [], closedNodeState;
if (this instanceof Duckdown) state = this;
@@ -386,11 +387,17 @@
// We'll leave it up to the state genus can determine what to do if
// it's mismatched - we're not going to be presumptuous!
state.currentNode.mismatched = true;
- state.closeCurrentNode(true);
+ closedNodeState = state.closeCurrentNode(true);
+
+ if (closedNodeState && closedNodeState.length)
+ closedNodeStates = closedNodeStates.concat(closedNodeState);
}
// And now close the actual node we're supposed to be listening for...
- state.closeCurrentNode();
+ closedNodeState = state.closeCurrentNode();
+
+ if (closedNodeState && closedNodeState.length)
+ closedNodeStates = closedNodeStates.concat(closedNodeState);
}
}
@@ -551,7 +558,7 @@
state.previousToken = state.currentToken;
// Return parser states for this token as a css-compatible class string.
- return state.parserStates.join(" ").toLowerCase().replace(/\_/ig,"-");
+ return state.parserStates.concat(closedNodeStates).join(" ").toLowerCase().replace(/\_/ig,"-");
};
// Compile from Duckdown intermediate format to the destination text format.
@@ -652,7 +659,8 @@
// Function for closing nodes...
Duckdown.prototype.closeCurrentNode = function(parentNodeClosed) {
var currentState = this.parserStates[this.parserStates.length-1],
- stateGenus = Grammar.stateList[currentState];
+ stateGenus = Grammar.stateList[currentState],
+ closedStateList = [];
var state = this, tmpTokenGenus = {}, tree = null;
@@ -790,7 +798,8 @@
state.nodeDepth --;
// Truncate parser state stack...
- state.parserStates.length = state.nodeDepth;
+ if (state.nodeDepth < state.parserStates.length)
+ closedStateList = state.parserStates.splice(state.nodeDepth - state.parserStates.length);
// Finally, do we swallow any token components that match?
// Check the state genus and act accordingly. If we destroy the token components,
@@ -822,6 +831,8 @@
state.currentToken = state.currentToken.substring(matchPoint);
}
}
+
+ return closedStateList;
};
// Helper function to do a reverse-lookup to find token info from a state name.

0 comments on commit fc5e0f7

Please sign in to comment.
Something went wrong with that request. Please try again.