Skip to content

Commit

Permalink
simplify closing nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Feb 16, 2020
1 parent f2169fa commit 4726d40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,7 @@ const HLJS = function(hljs) {
index = match.index + count;
}
processLexeme(codeToHighlight.substr(index));
for(current = top; current.parent; current = current.parent) { // close dangling modes
if (current.className) {
emitter.closeNode();
}
}
emitter.closeAllNodes();
emitter.collapse();
result = new HTMLRenderer(emitter, options).value();
return {
Expand Down
12 changes: 8 additions & 4 deletions src/lib/token_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class TokenTree {
get top() {
return this.stack[this.stack.length - 1];
}
push(node) {
add(node) {
this.top.children.push(node);
}
addKeyword(text, kind) {
Expand All @@ -20,24 +20,28 @@ export default class TokenTree {
addText(text) {
if (text === "") { return; }

this.push(text);
this.add(text);
}
addSublanguage({rootNode}, name) {
let node = rootNode;
delete node.root; // no longer a root node
node.kind = name;
node.sublanguage = true;
this.push(node);
this.add(node);
}
openNode(kind) {
var node = { kind, children: [] };
this.push(node);
this.add(node);
this.stack.push(node);
}
closeNode() {
if (this.stack.length > 1)
this.stack.pop();
}
closeAllNodes() {
while (this.stack.length > 1)
this.closeNode();
}


toJSON() {
Expand Down

0 comments on commit 4726d40

Please sign in to comment.