Skip to content

Add line comment syntax (%% to end of line)#104

Draft
dereuromark wants to merge 6 commits intomasterfrom
feature/line-comments
Draft

Add line comment syntax (%% to end of line)#104
dereuromark wants to merge 6 commits intomasterfrom
feature/line-comments

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

@dereuromark dereuromark commented Mar 16, 2026

Summary

Implements line comment syntax: %% extends to the end of the line and is ignored.

This is visible %% but this is a comment
%% This entire line is a comment
More visible text

Implementation

  • InlineParser::removeLineComments(): Strips %% to end of line before parsing inline content
  • BlockParser::tryParseLineComment(): Handles full-line comments (lines starting with %%)

The existing comment syntaxes ({% ... %} and %%% fenced) are preserved.

Context-Aware Parsing

The %% line comment is only recognized outside of protected contexts:

  • Code spans (`code %% here`)
  • Quoted attribute values ([text]{title="%% value"})
  • Link URLs ([link](url%%test))
  • Math spans ($x %% y$)
  • Escaped characters (\%\%)

Tests

Added LineCommentTest.php with 19 test cases covering:

  • Inline line comments
  • Full-line comments
  • Multiple line comments
  • Comments within paragraphs, headings, lists, block quotes
  • Protected contexts (code, attributes, links, math, escapes)

Refs jgm/djot#67, jgm/djot#384

=> Waiting for upstream "confirm"

Implements line comments that start with `%%` and extend to end of line:

- Inline: `Text before %% this is ignored`
- Full line: `%% This entire line is a comment`

Implementation:
- InlineParser: strips `%%` to end of line before parsing inline content
- BlockParser: handles full-line comments (lines starting with `%%`)

The existing comment syntaxes (`{% ... %}` and `%%%` fenced) are preserved.

Refs jgm/djot#67, jgm/djot#384
@dereuromark dereuromark added the enhancement New feature or request label Mar 16, 2026
@dereuromark dereuromark marked this pull request as draft March 16, 2026 17:15
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 98.29060% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.84%. Comparing base (844b948) to head (f1018f4).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Parser/InlineParser.php 98.13% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #104      +/-   ##
============================================
+ Coverage     93.76%   93.84%   +0.08%     
- Complexity     2341     2395      +54     
============================================
  Files            79       79              
  Lines          6205     6321     +116     
============================================
+ Hits           5818     5932     +114     
- Misses          387      389       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

dereuromark and others added 5 commits March 23, 2026 08:43
The %% line comment syntax was incorrectly stripping content from inside:
- Code spans (`code %% here`)
- Quoted attribute values ([text]{title="%% value"})
- Link URLs ([link](url%%test))
- Math spans ($x %% y$)

This change rewrites removeLineComments() to be context-aware, properly
skipping over:
- Backtick spans (code)
- Quoted strings (single and double)
- Parenthesized content (links)
- Curly brace blocks (attributes)
- Math delimiters ($ and $$)
- Escaped characters

Added 9 tests to cover these edge cases.
The block parser was incorrectly treating `{% comment %} text` as a
block-level comment, consuming the entire line and losing "text".

This fix updates `isCommentOpener()` to only treat a line as a block
comment when:
- The comment spans multiple lines (no closing %} on same line), OR
- The comment is alone on the line (nothing after %})

Single-line comments with content after them are now handled as inline
comments by the attribute parser, which correctly strips the comment
while preserving surrounding text.

Fixes:
- `{% comment %} text` now renders as `<p> text</p>`
- `{% one %} text {% two %}` now renders as `<p> text </p>`

Added 5 tests covering inline comment edge cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant