Skip to content

Support GitHub-style markup rendering - #6

Merged
posaune0423 merged 2 commits into
mainfrom
feature/github-markup-support
Mar 29, 2026
Merged

posaune0423 merged 2 commits into
mainfrom
feature/github-markup-support

Conversation

@posaune0423

@posaune0423 posaune0423 commented Mar 29, 2026 •

Copy link
Copy Markdown
Owner

This PR expands GitHub-style markup coverage in the rich HTML renderer with fixtures and regression tests for centered raw HTML wrappers, details/summary, picture/source, and math expressions.
It restores safe raw HTML more generically, preserves math in the plain/headless path, respects explicit img height attributes, and decodes double-escaped entities like   inside restored raw HTML.
It also makes make build refresh ./bin/mdv, updates the related docs and contract tests, and refreshes the tracked bin/mdv artifact.
Verification included cargo test --workspace --all-targets, cargo clippy --workspace --all-targets --all-features -- -D warnings, and make build && TERM=xterm-kitty ./bin/mdv ~/Work/daikolabs/marry-fun/README.md.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for mathematical expressions using inline ($...$) and display ($$...$$) math notation.
    • Extended HTML support to include <details> and <summary> elements for collapsible content.
    • Added support for responsive images using <picture> and <source> elements with media queries.
    • Improved HTML block alignment and centered image rendering with proper styling.
  • Bug Fixes

    • Fixed double-escaped HTML entity decoding in restored content.
    • Corrected image height attribute handling to prevent CSS overrides.
  • Documentation

    • Updated development and markdown feature documentation.

@coderabbitai

coderabbitai Bot commented Mar 29, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR extends markdown rendering with GitHub HTML restoration improvements and math expression support. Changes include: generalized raw HTML tag restoration (picture, source, details) with entity decoding; math parsing via Comrak extensions; CSS overrides for image alignment and math styling; build documentation clarification; and comprehensive test coverage across fixtures, integration, and unit tests.

Changes

Cohort / File(s) Summary
Math Support
src/render/markdown_pipeline.rs, src/render/markdown.rs, src/render/github_html/styles.rs
Added math_dollars and math_code GFM extension toggles. Extended collect_text_segments to convert NodeValue::Math into Markdown inline/display math syntax. Added CSS rules for inline math (white-space: nowrap) and display math (block layout, vertical margins, centered text, white-space: pre-wrap).
HTML Restoration & Postprocessing
src/render/github_html/postprocess.rs
Replaced permissive tag handling with generalized restore_block_tag approach. Added decode_double_escaped_entities to restore &amp;-escaped entities. Expanded support for <picture>, <source> tags with strict attribute parsing and srcset validation. Refactored attribute parsing via new split_tag_name, parse_attributes_strict, and parse_attributes_and_flags with ParsedTagAttributes struct.
Image & Alignment Styling
src/render/github_html/styles.rs
Enhanced CSS overrides: conditional height: auto only for images lacking height attribute; block-level rendering for single aligned images with horizontal margin/centering rules; preserved existing paragraph image styling.
Test Fixtures—HTML Blocks
tests/fixtures/gfm/html-centered-blocks/input.md, tests/fixtures/gfm/html-centered-blocks/expected-substrings.txt, tests/fixtures/gfm/html-details/input.md, tests/fixtures/gfm/html-details/expected-substrings.txt, tests/fixtures/gfm/html-picture/input.md, tests/fixtures/gfm/html-picture/expected-substrings.txt
Added fixtures for centered HTML blocks (<p align>), <details> with <summary>, and <picture> with <source> responsive image examples.
Test Fixtures—Math
tests/fixtures/gfm/math/input.md, tests/fixtures/gfm/math/expected-substrings.txt
Added inline and display math expression fixtures with expected HTML substrings for data-math-style spans.
Unit Tests—Rendering
tests/unit/render_pipeline/gfm_fixtures.rs, tests/unit/render_pipeline/github_html.rs
Added three GFM fixture rendering tests (centered-blocks, details, picture) and four build_github_html validation tests (image alignment, height attribute preservation, double-escaped entity decoding, math rendering with data-math-style).
Unit Tests—Snapshot & Normalization
tests/unit/render_pipeline/webkit_snapshot.rs, tests/unit/markdown_normalize.rs
Added two macOS WebKit snapshot tests for centered-block fixture asset rendering and explicit height attribute respect. Added plain document normalization test for math text preservation.
Integration Tests
tests/integration/render_features.rs, tests/integration/distribution_contract.rs
Added test for inline/display math expression visibility in headless rendering. Added test verifying make build refreshes local bin/mdv via cargo build --release and binary copy.
Build & Documentation
Makefile, docs/DEVELOPMENT.md, docs/MARKDOWN.md
Reordered Makefile build-tracked-bin dependency declaration (moved after platform-specific copy logic). Updated docs/DEVELOPMENT.md to clarify make build refreshes local bin/mdv copy; make build-tracked-bin is CI packaging alias. Added math extension documentation to docs/MARKDOWN.md.
Agent Memory
.agents/memory/lessons.md, .agents/memory/todo.md
Added validation lessons on HTML attribute/CSS override interactions and double-escaped entity persistence. Documented GitHub HTML restoration fixes, math rendering, and build contract verification checklist.

Sequence Diagram(s)

sequenceDiagram
    participant Parser as Markdown Parser
    participant Segment as collect_text_segments
    participant Pipeline as Render Pipeline
    participant CSS as CSS Styling
    participant Browser as Browser Output

    Parser->>Parser: Detect $...$ or $$...$$ syntax
    Parser->>Parser: Create NodeValue::Math(literal, flags)
    Parser->>Segment: Process Math node
    Segment->>Segment: Convert to $...$ or $$...$$ text
    Segment->>Pipeline: Emit InlineSegment with math text
    Pipeline->>Pipeline: Wrap in span[data-math-style]
    Pipeline->>CSS: Render HTML with data-math-style attr
    CSS->>CSS: Apply nowrap for inline math
    CSS->>CSS: Apply block layout for display math
    CSS->>Browser: Display formatted math
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🐰 Math and HTML dance together now,
Picture-perfect details revealed,
Dollar signs bloom in the markdown burrow,
Centered, styled, and beautifully sealed!
—RabbitBot 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Support GitHub-style markup rendering' is somewhat related to the main changes, covering math rendering, image handling, and HTML restoration. However, it is overly broad and does not highlight the primary technical changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/github-markup-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@posaune0423 posaune0423 self-assigned this Mar 29, 2026
@posaune0423 posaune0423 added the enhancement New feature or request label Mar 29, 2026
@posaune0423
posaune0423 merged commit 60d6074 into main Mar 29, 2026
2 of 3 checks passed
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