Skip to content

Add code syntax highlighting - #20

Merged
Arctis-Fireblight merged 5 commits into
Redot-Engine:masterfrom
Arctis-Fireblight:code-style
Jun 28, 2026
Merged

Add code syntax highlighting#20
Arctis-Fireblight merged 5 commits into
Redot-Engine:masterfrom
Arctis-Fireblight:code-style

Conversation

@Arctis-Fireblight

@Arctis-Fireblight Arctis-Fireblight commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Added syntax highlighting and a few misc formatting things on various docs pages.

Summary by CodeRabbit

  • New Features

    • Added syntax highlighting for code blocks in the documentation viewer.
    • Improved handling of complex rendered content like tabs and callouts in documentation pages.
  • Bug Fixes

    • Code blocks now render with better spacing, scrolling, and monospace styling.
    • Documentation highlighting now updates after page changes and dynamic content loads.
  • Documentation

    • Updated community channel guidance to point readers to the main community page.
    • Refined introductory formatting in the About section.

…ction

Integrates Prism.js for syntax highlighting across supported languages. Adds necessary CSS and JavaScript files. Updates `DocRendererService` to ensure HTML placeholders are processed for advanced rendering features like tabs and callouts. Introduces a JavaScript observer to trigger automatic highlighting on dynamic content. Updates related Razor components for seamless integration.
@Arctis-Fireblight Arctis-Fireblight self-assigned this Jun 28, 2026
@Arctis-Fireblight Arctis-Fireblight added the enhancement New feature or request label Jun 28, 2026
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Arctis-Fireblight, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 22 minutes and 59 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 603fb7c0-478e-4c91-b667-2f9a9ff9cf97

📥 Commits

Reviewing files that changed from the base of the PR and between d827e2e and b353e6a.

⛔ Files ignored due to path filters (1)
  • Redot-Documentation/wwwroot/lib/prism/prism-shell-session.min.js is excluded by !**/*.min.js
📒 Files selected for processing (2)
  • Redot-Documentation/Components/App.razor
  • Redot-Documentation/Services/DocRendererService.cs
📝 Walkthrough

Walkthrough

Adds Prism syntax highlighting to the documentation viewer. DocRendererService gains a placeholder-based HTML rendering pipeline so callout and tab blocks are deferred and injected post-Markdig. A new syntax-highlight.js applies Prism to rendered code blocks with retry and MutationObserver logic. App.razor registers Prism assets; DocViewer.razor triggers highlighting after render. Minor doc content edits included.

Changes

Prism Syntax Highlighting Integration

Layer / File(s) Summary
Placeholder-based HTML rendering
Redot-Documentation/Services/DocRendererService.cs
TransformMarkdown now initializes an htmlPlaceholders dictionary; TransformCallout and TransformTabsBlocks store generated HTML via StoreHtmlBlock and return placeholder tokens. RenderToHtmlAsync resolves all placeholders after Markdown.ToHtml.
Highlighting script and Prism CSS
Redot-Documentation/wwwroot/js/syntax-highlight.js, Redot-Documentation/wwwroot/lib/prism/prism-tomorrow.min.css, Redot-Documentation/wwwroot/app.css
New syntax-highlight.js IIFE implements highlightCode (locates .doc-viewer-content code elements, propagates language-* class to <pre>, calls Prism.highlightElement), exposes it on window, and adds scheduleHighlight (rAF retry up to MAX_RETRY_FRAMES) and ensureObserver (MutationObserver). Wired to DOMContentLoaded and enhancedload. Prism Tomorrow CSS theme added. .doc-viewer-content pre/code styles added.
Asset registration and Blazor wiring
Redot-Documentation/Components/App.razor, Redot-Documentation/Components/Pages/DocViewer.razor
App.razor adds the Prism CSS <link>, inline Prism.manual setup, Prism bundle <script> tags, and syntax-highlight.js. DocViewer.razor injects IJSRuntime and invokes highlightCode in OnAfterRenderAsync on first render.
Doc content edits
Redot-Documentation/docs/About/introduction.md, Redot-Documentation/docs/Community/channels.md
introduction.md replaces blank-line paragraph breaks with explicit <br/><br/> tags. channels.md replaces the community list with a redirect to the Redot website community page.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐇 Hop hop, a rainbow of tokens appears,
Prism scatters keywords and strings through the years,
Placeholders tucked in, then swapped at the end,
The MutationObserver watches each bend.
Tomorrow's dark theme lights the code just right—
This rabbit highlights syntax through the night! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding code syntax highlighting to the documentation site.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
Redot-Documentation/docs/About/introduction.md (1)

55-67: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider semantic paragraph breaks instead of presentational <br/>.

The three <br/><br/> tags add vertical spacing via presentational HTML. If the design intent is extra spacing between paragraphs, consider achieving this through CSS margin utilities or custom styles on the .doc-viewer-content container rather than inline breaks. This preserves semantic document structure and avoids screen-reader verbosity from explicit line breaks.

No change required if this is an intentional short-term compatibility measure.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Redot-Documentation/docs/About/introduction.md` around lines 55 - 67, The
introduction content uses repeated <br/><br/> tags for spacing, which is
presentational and hurts document semantics. Update the prose in introduction.md
to use real paragraph breaks or rely on styling from the doc viewer instead of
inline breaks, and keep the content structure within the Introduction section
semantically grouped. Use the surrounding introduction text and the
.doc-viewer-content styling approach as the guide when relocating the spacing
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Redot-Documentation/Components/App.razor`:
- Around line 23-28: The Prism script list in App.razor only loads language
components for C, C++, C#, and GDScript, so shell fenced code blocks are not
highlighted. Add the missing Prism shell language asset alongside the existing
prism-* includes in the App.razor script section, keeping the change near the
current Prism imports so ```shell fences are recognized.

In `@Redot-Documentation/Services/DocRendererService.cs`:
- Around line 46-52: The placeholder replacement loop in
DocRendererService.RenderMarkdown can hang if a replacement reintroduces a
token, so bound resolution instead of looping until no keys remain. Update the
logic around renderedHtml and transformedMarkdown.HtmlPlaceholders to use
collision-resistant placeholder tokens and limit replacement passes to the
number of placeholders (or another fixed cap), ensuring the loop always
terminates even when content contains deterministic placeholder-like text.
- Around line 99-106: The warning callout handling in
DocRendererService.TransformMarkdown is applied after TransformTabsBlocks, which
can hide :::warning blocks inside tab content from the regex. Reorder the
transforms so the warning Regex.Replace runs before the tab placeholder pass,
then call TransformTabsBlocks only once afterward, keeping the existing
TransformCallout and IconConstants.TipsIcon usage intact.

In `@Redot-Documentation/wwwroot/js/syntax-highlight.js`:
- Around line 24-38: The `highlightCode` flow is re-triggering itself because
`Prism.highlightElement` mutates the same code nodes and the `MutationObserver`
on `document.body` keeps scheduling repeats. Update the logic around
`codeBlocks.forEach(...)` and `window.Prism.highlightElement(codeBlock)` to
prevent reprocessing, either by marking already highlighted blocks or
temporarily disconnecting/reconnecting the observer while highlighting. Use the
existing `highlightCode` and observer setup in `syntax-highlight.js` to keep the
same blocks from being highlighted more than once.

In `@Redot-Documentation/wwwroot/lib/prism/prism-tomorrow.min.css`:
- Line 1: The Prism theme stylesheet still uses the deprecated word-wrap
property in the base code/pre rule, which stylelint flags. Update the shared
syntax-highlighting selector block for code[class*=language-] and
pre[class*=language-] to use overflow-wrap instead of word-wrap so the minified
theme stays lint-clean while preserving wrapping behavior.

---

Nitpick comments:
In `@Redot-Documentation/docs/About/introduction.md`:
- Around line 55-67: The introduction content uses repeated <br/><br/> tags for
spacing, which is presentational and hurts document semantics. Update the prose
in introduction.md to use real paragraph breaks or rely on styling from the doc
viewer instead of inline breaks, and keep the content structure within the
Introduction section semantically grouped. Use the surrounding introduction text
and the .doc-viewer-content styling approach as the guide when relocating the
spacing behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e3b1aaa3-f93d-40b3-91eb-e1f68fb62555

📥 Commits

Reviewing files that changed from the base of the PR and between 6fc7887 and d827e2e.

⛔ Files ignored due to path filters (6)
  • Redot-Documentation/wwwroot/lib/prism/prism-c.min.js is excluded by !**/*.min.js
  • Redot-Documentation/wwwroot/lib/prism/prism-clike.min.js is excluded by !**/*.min.js
  • Redot-Documentation/wwwroot/lib/prism/prism-core.min.js is excluded by !**/*.min.js
  • Redot-Documentation/wwwroot/lib/prism/prism-cpp.min.js is excluded by !**/*.min.js
  • Redot-Documentation/wwwroot/lib/prism/prism-csharp.min.js is excluded by !**/*.min.js
  • Redot-Documentation/wwwroot/lib/prism/prism-gdscript.min.js is excluded by !**/*.min.js
📒 Files selected for processing (8)
  • Redot-Documentation/Components/App.razor
  • Redot-Documentation/Components/Pages/DocViewer.razor
  • Redot-Documentation/Services/DocRendererService.cs
  • Redot-Documentation/docs/About/introduction.md
  • Redot-Documentation/docs/Community/channels.md
  • Redot-Documentation/wwwroot/app.css
  • Redot-Documentation/wwwroot/js/syntax-highlight.js
  • Redot-Documentation/wwwroot/lib/prism/prism-tomorrow.min.css

Comment thread Redot-Documentation/Components/App.razor
Comment thread Redot-Documentation/Services/DocRendererService.cs Outdated
Comment thread Redot-Documentation/Services/DocRendererService.cs
Comment thread Redot-Documentation/wwwroot/js/syntax-highlight.js
Comment thread Redot-Documentation/wwwroot/lib/prism/prism-tomorrow.min.css
…g in DocRendererService

Integrates Prism.js support for shell-session syntax in documentation. Updates `DocRendererService` for more robust placeholder replacement using unique GUIDs, enhancing reliability of HTML block rendering.
@Arctis-Fireblight
Arctis-Fireblight merged commit 2e95fb4 into Redot-Engine:master Jun 28, 2026
4 checks passed
@Arctis-Fireblight
Arctis-Fireblight deleted the code-style branch June 28, 2026 10:04
This was referenced Jun 28, 2026
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