Skip to content

Conversation

@risu729
Copy link
Contributor

@risu729 risu729 commented Nov 27, 2025

Fixes jdx/mise#6949


Note

Update the markdown escape filter to detect fenced code blocks and avoid escaping within them.

  • Markdown Rendering (lib/src/docs/markdown/renderer.rs):
    • Escape filter (escape_md):
      • Detects fenced code blocks using lines starting with ``` and tracks in_code_block state.
      • Skips HTML escaping (e.g., < to &lt;) for lines inside fenced blocks; leaves fence lines unchanged.
      • Previously only excluded indented code blocks; now also respects fenced code blocks.

Written by Cursor Bugbot for commit e3ccc18. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings November 27, 2025 12:28
@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

❌ Patch coverage is 90.31414% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.26%. Comparing base (5a58a16) to head (bbfcf91).

Files with missing lines Patch % Lines
lib/src/docs/markdown/renderer.rs 90.31% 16 Missing and 21 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #386      +/-   ##
==========================================
+ Coverage   71.92%   73.26%   +1.34%     
==========================================
  Files          45       45              
  Lines        4495     4855     +360     
  Branches     4495     4855     +360     
==========================================
+ Hits         3233     3557     +324     
- Misses        945      960      +15     
- Partials      317      338      +21     

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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request attempts to fix escaping of < characters inside fenced code blocks (delimited by ```) in the markdown renderer. The change adds state tracking to detect when processing lines within fenced code blocks, so that HTML escaping can be skipped for those lines.

Key changes:

  • Adds in_code_block boolean state variable to track whether currently inside a fenced code block
  • Modifies the escape_md filter to toggle the state when encountering ``` fences
  • Extends the early return condition to skip escaping when in_code_block is true

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jdx
Copy link
Owner

jdx commented Nov 27, 2025

bugbot run

if line.trim_start().starts_with("```") {
in_code_block = !in_code_block;
return line.to_string();
}
Copy link

Choose a reason for hiding this comment

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

Bug: Indented code content incorrectly detected as fence delimiter

The check line.trim_start().starts_with("```") incorrectly matches lines that are content within indented code blocks (4+ spaces of indentation). In Markdown, fenced code block markers can only have 0-3 spaces of indentation; lines with 4+ spaces are indented code block content. If such content happens to contain "```", the in_code_block state gets toggled incorrectly, causing subsequent non-code text to skip `<` escaping when it shouldn't. The fence detection should either check the indentation condition first or validate that there are fewer than 4 leading spaces.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't know this, should we support it?

Copy link
Owner

Choose a reason for hiding this comment

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

up to you, we could do it later if you want

@risu729 risu729 changed the title fix(generate): don't escape < in fenced code blocks fix(generate): don't escape < in multiline code blocks Nov 28, 2025
@risu729 risu729 force-pushed the ignore-fenced-code-blocks-lt branch from 95379e1 to d258b14 Compare November 28, 2025 15:50
@risu729 risu729 marked this pull request as draft November 28, 2025 16:00
@risu729 risu729 force-pushed the ignore-fenced-code-blocks-lt branch from 7a55c5f to 2cb8402 Compare November 28, 2025 18:34
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.

2 participants