A begin-block / end-block delimiter that starts at column 0 is blanked but its line is not removed, leaving a stray empty line in the displayed source. Delimiters that are indented (which is the case for every fragment in the current demos) are removed correctly, which is why this has gone unnoticed.
Steps to reproduce
Add a fragment to a demo source with the delimiters unindented:
public class SampleDemo extends Div {
public SampleDemo() {
// begin-block first
Div first = new Div(new Text("First"));
add(first);
// end-block
add(other);
}
}
Expected (same as when the delimiters are indented):
Div first = new Div(new Text("First"));
add(first);
add(other);
Actual — one blank line for each delimiter:
Div first = new Div(new Text("First"));
add(other);
If the delimiter is additionally preceded by a blank line, the result is two consecutive blank lines instead of one.
Cause
process() clears the delimiter's comment node and then calls trimEnd(i-1) to remove the newline and indentation preceding it, in code-viewer.ts:
node.textContent = node.textContent.replaceAll(/\n[\t\x20]+$/g, '');
The [\t\x20]+ requires at least one space or tab after the newline, so the rule implemented is "remove the delimiter's line if it is indented" rather than "remove the delimiter's line". When the delimiter is at column 0 the preceding text node is exactly "\n", nothing matches, and the newline survives.
Suggested fix
Make the indentation optional:
-node.textContent = node.textContent.replaceAll(/\n[\t\x20]+$/g, '');
+node.textContent = node.textContent.replaceAll(/\n[\t\x20]*$/g, '');
The match stays anchored at $, so this removes exactly the delimiter's own newline and never a blank line written by the author. It is a no-op for every indented delimiter, i.e. for all fragments currently in the repository.
Notes
This is independent of #98, but it becomes unavoidable there: CSS has no line comments and rules normally start at column 0, so every CSS fragment delimiter hits this path.
A
begin-block/end-blockdelimiter that starts at column 0 is blanked but its line is not removed, leaving a stray empty line in the displayed source. Delimiters that are indented (which is the case for every fragment in the current demos) are removed correctly, which is why this has gone unnoticed.Steps to reproduce
Add a fragment to a demo source with the delimiters unindented:
Expected (same as when the delimiters are indented):
Actual — one blank line for each delimiter:
If the delimiter is additionally preceded by a blank line, the result is two consecutive blank lines instead of one.
Cause
process()clears the delimiter's comment node and then callstrimEnd(i-1)to remove the newline and indentation preceding it, incode-viewer.ts:The
[\t\x20]+requires at least one space or tab after the newline, so the rule implemented is "remove the delimiter's line if it is indented" rather than "remove the delimiter's line". When the delimiter is at column 0 the preceding text node is exactly"\n", nothing matches, and the newline survives.Suggested fix
Make the indentation optional:
The match stays anchored at
$, so this removes exactly the delimiter's own newline and never a blank line written by the author. It is a no-op for every indented delimiter, i.e. for all fragments currently in the repository.Notes
This is independent of #98, but it becomes unavoidable there: CSS has no line comments and rules normally start at column 0, so every CSS fragment delimiter hits this path.