Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

continue processing ecmarkdown after comments #479

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>