Skip to content

Match djot.js on five parser edge cases (djot.js PR 137 test corpus) - #264

Merged
dereuromark merged 1 commit into
masterfrom
pr137-divergences
Jul 18, 2026
Merged

Match djot.js on five parser edge cases (djot.js PR 137 test corpus)#264
dereuromark merged 1 commit into
masterfrom
pr137-divergences

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

Ports the test cases from the pending djot.js PR More test case suggestions from cdjot regressions into the official test suite and fixes the five cases where djot-php diverged from djot.js. All expected outputs were verified against djot.js main (commit 84a4b02), not just taken from the PR.

Fixes

  • Invalid attribute specs render literally. Identifiers, class names, keys, and unquoted values only allow ASCII alphanumerics plus _, :, -. Any other character (e.g. {#a<b}) invalidates the entire spec, which stays literal text instead of leaking into attribute context. Applied on the block path, the inline word-attachment path, and trailing attribute blocks after spans/links/emphasis/code. New AttributeParser::isValid() implements the whole-spec grammar check.
  • Bare : starts a definition list. A : followed by end of input produces an empty <dl><dt></dt><dd></dd></dl> instead of a paragraph (fuzz-crash class found in cdjot).
  • Trailing backslash at end of content is a hard break. para\ at end of input now emits <br> instead of a literal backslash. Also holds at end of a paragraph mid-document and in headings, matching djot.js.
  • Bare # marker line continues a heading. # h / # / # x is one heading with content h/x (id h-x), not two sections.
  • Table separator cells must start immediately after |. | --- | --- | (leading space) is an ordinary data row; only |---|---| promotes the previous row to a header. Trailing space before the next | remains allowed, matching djot.js pattRowSep.

One existing expectation was corrected: AttributeParserTest previously asserted that an invalid unquoted value (invalid=foo.bar) is skipped while keeping the remaining attributes; djot.js invalidates the whole spec, so the test now expects literal output.

Notes

  • Where djot-php deliberately keeps a bracketed run fully literal next to an invalid attribute block (the documented [x]{???} convention), that convention is preserved: [x]{#a<b} renders fully literal, while djot.js keeps the span and renders only the braces literally.
  • Two adjacent divergences surfaced while testing but are pre-existing and out of scope here: table cells trim trailing backslash-space differently than djot.js (| a\ |), and an empty higher-level heading between two headings sections differently (# h / ## / # x).

- Invalid characters in an attribute spec now invalidate the whole
  spec, which renders as literal text (block and inline paths)
- A bare ":" line starts a definition list with empty term/definition
- A trailing backslash at end of content produces a hard break
- A bare "#" marker line continues a heading without adding content
- Table separator cells must start immediately after "|"; a leading
  space makes the row an ordinary data row

Test cases ported from the pending djot.js PR "More test case
suggestions from cdjot regressions" (jgm/djot.js PR 137); expected
outputs verified against djot.js main.
@dereuromark dereuromark added the bug Something isn't working label Jul 18, 2026
@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.39%. Comparing base (2cb432a) to head (c366e36).

Files with missing lines Patch % Lines
src/Parser/BlockParser.php 93.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #264      +/-   ##
============================================
+ Coverage     92.37%   92.39%   +0.02%     
- Complexity     3660     3668       +8     
============================================
  Files           109      109              
  Lines         10379    10407      +28     
============================================
+ Hits           9588     9616      +28     
  Misses          791      791              

☔ View full report in Codecov by Harness.
📢 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
dereuromark merged commit 3ac5a79 into master Jul 18, 2026
6 checks passed
@dereuromark
dereuromark deleted the pr137-divergences branch July 18, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant