Skip to content

Commit

Permalink
continue processing ecmarkdown after comments (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored Aug 30, 2022
1 parent 33c04a6 commit e1cdab9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1955,9 +1955,7 @@ async function walk(walker: TreeWalker, context: Context) {
previousInNoEmd = false;
}

if (context.node.nodeType === 3) {
// walked to a text node

if (context.node.nodeType === 3 /* Node.TEXT_NODE */) {
if (context.node.textContent!.trim().length === 0) return; // skip empty nodes; nothing to do!

const clause = context.clauseStack[context.clauseStack.length - 1] || context.spec;
Expand All @@ -1966,13 +1964,19 @@ async function walk(walker: TreeWalker, context: Context) {
// new nodes as a result of emd processing should be skipped
context.inNoEmd = true;
let node = context.node as Node | null;
while (node && !node.nextSibling) {
function nextRealSibling(node: Node | null) {
while (node?.nextSibling?.nodeType === 8 /* Node.COMMENT_NODE */) {
node = node.nextSibling;
}
return node?.nextSibling;
}
while (node && !nextRealSibling(node)) {
node = node.parentNode;
}

if (node) {
// inNoEmd will be set to false when we walk to this node
context.followingEmd = node.nextSibling;
context.followingEmd = nextRealSibling(node)!;
}
// else, there's no more nodes to process and inNoEmd does not need to be tracked

Expand Down
14 changes: 14 additions & 0 deletions test/baselines/generated-reference/ecmarkdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
<ul>
<li><span>Toggle shortcuts help</span><code>?</code></li>
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>

<li><span>Jump to search box</span><code>/</code></li>
</ul></div><div id="spec-container">
<emu-clause id="sec-foo">
<h1><span class="secnum">1</span> ecmarkdown basics</h1>
<p>ecmarkdown like <var>v</var> works before <!-- a comment --> and after comments <var>v</var>.</p>
</emu-clause>

</div></body>
10 changes: 10 additions & 0 deletions test/baselines/sources/ecmarkdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<pre class=metadata>
toc: false
copyright: false
assets: none
</pre>
<emu-clause id="sec-foo">
<h1>ecmarkdown basics</h1>
<p>ecmarkdown like _v_ works before <!-- a comment --> and after comments _v_.</p>
</emu-clause>

0 comments on commit e1cdab9

Please sign in to comment.