[PR #3243] [MERGED] fix: parse markdown headings in files with CRLF line endings #5859

Closed
opened 2026-10-22 04:20:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3243
Author: @kolacheee
Created: 7/5/2026
Status: ✅ Merged
Merged: 7/5/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/markdown-crlf-line-endings


📝 Commits (1)

  • 0a4f349 fix: parse markdown headings in files with CRLF line endings

📊 Changes

1 file changed (+4 additions, -1 deletions)

View changed files

📝 packages/client/src/lib/markdown.tsx (+4 -1)

📄 Description

Fixes #3242

Summary

renderMarkdownBlocks split content on "\n" only, so text with Windows CRLF line endings left a trailing \r on every line. The heading regex (/^(#{1,6})\s+(.+)$/) cannot match across a carriage return, so headings in CRLF files rendered as literal # ... plain text. Now the renderer splits on /\r?\n/, making CRLF and LF input parse identically.

Why

The seeded CREDITS.md in Game Assets arrives with CRLF endings on Windows (git converts it at checkout, and the seeder copies it byte-for-byte), so every Windows install shows broken headings when previewing it — while tables in the same file render fine, because the table parser happens to .trim() each line. Any markdown file written by a Windows editor and imported into game assets hits the same problem. Fixing it at the line-split also protects the parser's other line-anchored patterns that don't trim, instead of patching regexes one by one.

Known limitations

The separate applyInlineMarkdownHTML path (sanitized-HTML pipeline where newlines are already <br> tags) is untouched — whether \r can survive into that pipeline depends on the upstream sanitizer and there is no observed repro there.

Note: the full styled result in the file preview also needs #3241 (the preview's CSS scoping fix, separate PR). This fix is observable independently: with it, the # marks are consumed and real <h1>–<h6> elements are emitted.

Test plan

  • Manually verify in browser (Windows install): Settings → Game Assets → Asset Browser → open the seeded CREDITS.md → Preview shows "Game Assets Credits", "Music", etc. as headings with no literal # marks
  • Manually verify no regression for LF content: create a new markdown file in-app with # Heading, a list, and a table — everything still renders as before
  • Manually verify a code fence in a CRLF file still renders as a code block
  • Capture before/after screenshots for this PR

pnpm check passes locally.

UI Evidence

How credits.md appears now:
image

With both this and #3241 applied:
image

Summary by CodeRabbit

  • Bug Fixes
    • Improved markdown rendering to handle both Windows and Unix line endings consistently.
    • Fixed an issue where some headings and other line-based markdown patterns could fail to render correctly when content included carriage returns.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/3243 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 7/5/2026 **Status:** ✅ Merged **Merged:** 7/5/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/markdown-crlf-line-endings` --- ### 📝 Commits (1) - [`0a4f349`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0a4f3497894d26f1bcc7c3ad966857366d76724e) fix: parse markdown headings in files with CRLF line endings ### 📊 Changes **1 file changed** (+4 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/lib/markdown.tsx` (+4 -1) </details> ### 📄 Description Fixes #3242 ## Summary `renderMarkdownBlocks` split content on `"\n"` only, so text with Windows CRLF line endings left a trailing `\r` on every line. The heading regex (`/^(#{1,6})\s+(.+)$/`) cannot match across a carriage return, so headings in CRLF files rendered as literal `# ...` plain text. Now the renderer splits on `/\r?\n/`, making CRLF and LF input parse identically. ## Why The seeded `CREDITS.md` in Game Assets arrives with CRLF endings on Windows (git converts it at checkout, and the seeder copies it byte-for-byte), so every Windows install shows broken headings when previewing it — while tables in the same file render fine, because the table parser happens to `.trim()` each line. Any markdown file written by a Windows editor and imported into game assets hits the same problem. Fixing it at the line-split also protects the parser's other line-anchored patterns that don't trim, instead of patching regexes one by one. ## Known limitations The separate `applyInlineMarkdownHTML` path (sanitized-HTML pipeline where newlines are already `<br>` tags) is untouched — whether `\r` can survive into that pipeline depends on the upstream sanitizer and there is no observed repro there. Note: the full styled result in the file preview also needs #3241 (the preview's CSS scoping fix, separate PR). This fix is observable independently: with it, the `#` marks are consumed and real `<h1>`–`<h6>` elements are emitted. ## Test plan - [x] Manually verify in browser (Windows install): Settings → Game Assets → Asset Browser → open the seeded `CREDITS.md` → Preview shows "Game Assets Credits", "Music", etc. as headings with no literal `#` marks - [x] Manually verify no regression for LF content: create a new markdown file in-app with `# Heading`, a list, and a table — everything still renders as before - [x] Manually verify a code fence in a CRLF file still renders as a code block - [x] Capture before/after screenshots for this PR `pnpm check` passes locally. ## UI Evidence How `credits.md` appears now: <img width="1021" height="806" alt="image" src="https://github.com/user-attachments/assets/25367de9-7ff4-4365-af7e-b151b64abc82" /> With both this and #3241 applied: <img width="1024" height="811" alt="image" src="https://github.com/user-attachments/assets/ccc2a8a3-3a11-40f6-8587-7ffc6ebbd019" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved markdown rendering to handle both Windows and Unix line endings consistently. * Fixed an issue where some headings and other line-based markdown patterns could fail to render correctly when content included carriage returns. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:20:14 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5859
No description provided.