Add line comment syntax (%% to end of line)#104
Draft
dereuromark wants to merge 6 commits intomasterfrom
Draft
Conversation
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
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements line comment syntax:
%%extends to the end of the line and is ignored.Implementation
InlineParser::removeLineComments(): Strips%%to end of line before parsing inline contentBlockParser::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 %% here`)[text]{title="%% value"})[link](url%%test))$x %% y$)\%\%)Tests
Added
LineCommentTest.phpwith 19 test cases covering:Refs jgm/djot#67, jgm/djot#384
=> Waiting for upstream "confirm"