Skip to content

Add extended round-trip support for links and inline elements#157

Merged
dereuromark merged 2 commits intomasterfrom
feature/extended-round-trip-support
Apr 1, 2026
Merged

Add extended round-trip support for links and inline elements#157
dereuromark merged 2 commits intomasterfrom
feature/extended-round-trip-support

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

@dereuromark dereuromark commented Apr 1, 2026

Summary

This PR significantly extends the round-trip (Djot → HTML → Djot) capabilities:

  • Reference links: [text][ref] and [text][] syntax now round-trips via data-djot-ref attribute
  • Autolinks: <url> and <email> syntax now round-trips via data-djot-autolink attribute
  • Custom heading IDs: {#custom-id} on headings now round-trips via data-djot-explicit-id attribute
  • Mentions: @username syntax round-trips via existing data-username attribute detection
  • Footnotes: [^label] and [^label]: content syntax now round-trips via data-djot-footnote-label attribute
  • Admonitions: ::: type div syntax with AdmonitionExtension now round-trips via data-djot-admonition-* attributes
  • Tables: Fixed separator format (compact, 2-dash minimum)
  • Inline code: Fixed spacing for code containing backticks

Changes

New round-trip features:

  • Reference links store label on Link/Image nodes, HtmlToDjot reconstructs [text][ref] syntax and outputs reference definitions at document end
  • Autolinks marked with isAutolink flag, HtmlToDjot outputs <url> syntax
  • Section explicit IDs combined with heading attributes in HtmlToDjot
  • Footnotes preserve [^label] references and [^label]: content definitions via data-djot-footnote-label attributes
  • Admonitions preserve ::: type div syntax including custom titles and collapsible state via data-djot-admonition-* attributes

Bug fixes:

  • Inline code with backticks no longer double-spaces
  • Table separators use compact format matching Djot spec

Documentation:

  • Updated round-trip section with all new features
  • Added extension support section
  • Added round-trip limitations section

Testing

  • Added 69 round-trip tests covering all features
  • All 2025 existing tests pass

- Reference links: Store reference label on Link/Image nodes and emit
  data-djot-ref attribute. HtmlToDjot reconstructs [text][ref] syntax
  and outputs reference definitions at document end.

- Autolinks: Mark autolinks with isAutolink flag and emit
  data-djot-autolink attribute. HtmlToDjot outputs <url> syntax.

- Custom heading IDs: Emit data-djot-explicit-id on sections with
  explicit IDs. HtmlToDjot combines section ID with heading attributes.

- Mentions: HtmlToDjot detects data-username attribute to restore
  @username syntax.

- Tables: Changed separator format to compact (no padding spaces),
  allow 2-dash minimum width.

- Inline code: Fixed spacing for code containing backticks.

- Documentation: Updated round-trip section with new features,
  extension support, and limitations.

- Tests: Added 56 round-trip tests covering all new features.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 92.11618% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.74%. Comparing base (83e4efc) to head (c4fb40a).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Converter/HtmlToDjot.php 91.05% 17 Missing ⚠️
src/Extension/AdmonitionExtension.php 90.00% 1 Missing ⚠️
src/Renderer/HtmlRenderer.php 95.45% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #157      +/-   ##
============================================
- Coverage     93.77%   93.74%   -0.03%     
- Complexity     2874     2980     +106     
============================================
  Files            92       92              
  Lines          7466     7691     +225     
============================================
+ Hits           7001     7210     +209     
- Misses          465      481      +16     

☔ 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.

- Add data-djot-footnote-label attribute to footnote references and
  definitions for preserving [^label] syntax during round-trips
- Update HtmlToDjot to detect and process doc-endnotes section,
  extracting footnote definitions with backlinks removed
- Add data-djot-admonition-type attribute to AdmonitionExtension
  for preserving ::: type div syntax during round-trips
- Update HtmlToDjot to detect and process admonition divs and
  collapsible details elements, reconstructing original syntax
- Add 13 new round-trip tests for footnotes and admonitions
- Update documentation with new round-trip features
@dereuromark dereuromark merged commit 51a4c33 into master Apr 1, 2026
4 of 6 checks passed
@dereuromark dereuromark deleted the feature/extended-round-trip-support branch April 1, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant