Skip to content

Render Markdig MathInline and MathBlock nodes#145

Merged
boxofyellow merged 3 commits into
mainfrom
copilot/markdig-consider-render-math-nodes
May 17, 2026
Merged

Render Markdig MathInline and MathBlock nodes#145
boxofyellow merged 3 commits into
mainfrom
copilot/markdig-consider-render-math-nodes

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

UseAdvancedExtensions() enables Markdig's mathematics extension, which parses $...$ into MathInline and $$...$$ into MathBlock. Neither type had a registered ConsoleObjectRenderer, so all math content was silently dropped — leaving unexplained gaps in any document containing math.

Renderers

  • ConsoleMathInlineRenderer (one-liner in ConsoleObjectRenderers.cs) wraps MathInline.Content with the DisplayOptions.MathInline style, mirroring ConsoleCodeInlineRenderer.
  • ConsoleMathBlockRenderer (dedicated file) uses a fenced presentation like ConsoleCodeBlockRenderer, with DisplayOptions.MathBlock and an optional math label gated on ShowMathBlockLabel.

Registration order

MathBlock extends FencedCodeBlock, and Markdig's MarkdownObjectRenderer.Accept uses type assignability — so ConsoleMathBlockRenderer must precede ConsoleCodeBlockRenderer in the list, otherwise the code-block renderer would claim the type. A comment in ConsoleRenderer.cs records this.

DisplayOptions

New properties (with Clone() updates):

  • MathInline, MathBlock — text styles (default green on purple to differentiate from CodeInLine/CodeBlock's yellow on blue).
  • ShowMathBlockLabel (default false), MathBlockLabel, MathBlockLabelText ("math") — opt-in language-style label, analogous to ShowFencedCodeBlockInfo / FencedCodeBlockInfo.

Tests / fixtures

  • New mathInline.md / .txt and mathBlock.md / .txt snapshot pairs.
  • RendererTests_MathInlineTest and RendererTests_MathBlockTest with [DataRow] for default + crazy styles.
  • m_crazyOptions extended with the new properties (incl. ShowMathBlockLabel = true).
  • bracketEscaping.md extended with $[test30]…$ and $$[test31]…$$; bracketEscaping.txt regenerated.

Docs / example

  • example.md: new ## Mathematics section and Mathematics TODO entry.
  • CHANGELOG.md: entry under Upcoming Changes → Renderers.
internal class ConsoleMathInlineRenderer : ConsoleObjectRenderer<MathInline>
{
    protected override void Write(ConsoleRenderer renderer, MathInline obj)
        => renderer
            .AddInLine($"[{renderer.Options.MathInline.ToSpectreStyle().ToMarkup()}]")
            .WriteEscape(ref obj.Content)
            .AddInLine("[/]");
}

Copilot AI linked an issue May 16, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add renderers for MathInline and MathBlock nodes Render Markdig MathInline and MathBlock nodes May 16, 2026
Copilot AI requested a review from boxofyellow May 16, 2026 15:32
Copy link
Copy Markdown
Owner

@boxofyellow boxofyellow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please check out this comment.

Comment thread DisplayOptions.cs Outdated
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot please check out this comment.

Addressed in 7b43580 — see reply on the inline thread.

Copilot AI requested a review from boxofyellow May 17, 2026 00:32
Copy link
Copy Markdown
Owner

@boxofyellow boxofyellow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot in 7b43580 you removed ShowMathBlockLabel and change the default value for label property, but the old value is still referenced in the PRs description.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot in 7b43580 you removed ShowMathBlockLabel and change the default value for label pro...

Updated the PR description — removed the ShowMathBlockLabel bullet and the "math" default, and noted the label is now gated on !string.IsNullOrEmpty(MathBlockLabelText) (default string.Empty).

Copilot AI requested a review from boxofyellow May 17, 2026 01:04
Copy link
Copy Markdown
Owner

@boxofyellow boxofyellow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This PR need to be rebased (not just having master merged on top). However you will not have permission to forcepush changes.

Please checkout the main branch, create a new branch and then replay this PRs commits onto top of that new branch while addressing conflicts.

When you are done please let me know the name of the new branch you created.

Copilot AI and others added 2 commits May 17, 2026 02:39
Co-authored-by: boxofyellow <54955040+boxofyellow@users.noreply.github.com>
Co-authored-by: boxofyellow <54955040+boxofyellow@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot This PR need to be rebased (not just having master merged on top). However you will not have permission to forcepush changes.

Please checkout the main branch, create a new branch and then re...

Done. The rebased branch is copilot/markdig-consider-render-math-nodes-rebased (tip f370c11), branched from current main (5c986e4) with the two PR commits replayed.

Resolved conflicts:

  • docs/CHANGELOG.md — kept both Renderers entries; math entry now references PR Render Markdig MathInline and MathBlock nodes #145.
  • ObjectRenderers/ConsoleRenderer.cs — kept the new ConsoleAbbreviationInlineRenderer() from main alongside ConsoleMathBlockRenderer() (ordered before ConsoleCodeBlockRenderer).
  • ConsoleMarkdownRenderer.Example/data/example.md — kept Abbreviations + Figures TODO items and added Mathematics.
  • ConsoleMarkdownRenderer.Tests/resources/bracketEscaping.{md,txt} — renumbered the math identifiers to [test33] / [test34] since [test30][test32] are now used by the abbreviation/figure cases on main; regenerated the .txt accordingly.

All 167 unit tests (ConsoleMarkdownRenderer.Tests, net8.0) and 21 example tests pass.

Copilot AI requested a review from boxofyellow May 17, 2026 02:40
@boxofyellow boxofyellow force-pushed the copilot/markdig-consider-render-math-nodes branch from 7b43580 to f370c11 Compare May 17, 2026 02:56
@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.92%. Comparing base (4dc9fc6) to head (b6d867d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #145      +/-   ##
==========================================
+ Coverage   95.81%   95.92%   +0.11%     
==========================================
  Files          30       31       +1     
  Lines        1696     1743      +47     
  Branches      179      182       +3     
==========================================
+ Hits         1625     1672      +47     
  Misses         46       46              
  Partials       25       25              

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

Comment thread docs/CHANGELOG.md Outdated
Comment thread docs/CHANGELOG.md Outdated
Co-authored-by: boxofyellow <54955040+boxofyellow@users.noreply.github.com>
@boxofyellow boxofyellow marked this pull request as ready for review May 17, 2026 03:08
@boxofyellow boxofyellow merged commit bb164d3 into main May 17, 2026
12 checks passed
@boxofyellow boxofyellow deleted the copilot/markdig-consider-render-math-nodes branch May 17, 2026 03:08
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.

[Markdig] Consider rendering MathInline and MathBlock nodes

2 participants