[GH-ISSUE #3242] Markdown headings render as literal # text when a file has Windows (CRLF) line endings #1742

Closed
opened 2026-10-21 05:42:11 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @kolacheee on GitHub (Jul 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3242

Originally assigned to: @kolacheee on GitHub.

What happens

When the markdown renderer is given text with Windows-style line endings (CRLF, \r\n), headings are not converted — the preview shows the literal text # Game Assets Credits at body-text size instead of a styled heading. Tables, bold, and inline code in the same file render fine, which makes the broken headings stand out.

Try it yourself (on a Windows install)

  1. Open Settings → Game Assets → Asset Browser.
  2. Open the seeded CREDITS.md (every install has one) — it opens straight into Preview.
  3. The tables render with borders, but every heading shows as a literal # ... / ## ... line.
  4. For contrast: create a new markdown file in the same browser, type # Hello, and preview it — that heading converts fine, because files created in-app use plain \n line endings.

Why it happens

renderMarkdownBlocks in packages/client/src/lib/markdown.tsx splits content on "\n" only (line 378). For a CRLF file, every line keeps a trailing \r. The heading regex /^(#{1,6})\s+(.+)$/ can't match across that carriage return (in JavaScript regexes, . and $ stop at \r), so heading lines fall through and render as plain paragraph text. The table parser happens to call .trim() on each line first — which strips the \r — so tables work, headings don't.

The seeded CREDITS.md gets CRLF endings on Windows because git converts text files at checkout and the seeder copies the file byte-for-byte. Any markdown file written by a Windows editor and dropped into game assets hits the same problem. Chat messages are unaffected (typed/streamed content uses \n).

Fix

One-line change: split on /\r?\n/ instead of "\n" so CRLF and LF input parse identically. This also protects the other line-anchored patterns in the block parser that don't trim. Related: #3240 fixed the preview's missing styles; this bug is independent of that one (the heading # marks survive even with styling fixed). I'm taking this one (kolacheee) — PR to staging incoming.

Originally created by @kolacheee on GitHub (Jul 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3242 Originally assigned to: @kolacheee on GitHub. **What happens** When the markdown renderer is given text with Windows-style line endings (CRLF, `\r\n`), headings are not converted — the preview shows the literal text `# Game Assets Credits` at body-text size instead of a styled heading. Tables, bold, and inline code in the same file render fine, which makes the broken headings stand out. **Try it yourself** (on a Windows install) 1. Open **Settings → Game Assets → Asset Browser**. 2. Open the seeded `CREDITS.md` (every install has one) — it opens straight into Preview. 3. The tables render with borders, but every heading shows as a literal `# ...` / `## ...` line. 4. For contrast: create a new markdown file in the same browser, type `# Hello`, and preview it — that heading converts fine, because files created in-app use plain `\n` line endings. **Why it happens** `renderMarkdownBlocks` in `packages/client/src/lib/markdown.tsx` splits content on `"\n"` only (line 378). For a CRLF file, every line keeps a trailing `\r`. The heading regex `/^(#{1,6})\s+(.+)$/` can't match across that carriage return (in JavaScript regexes, `.` and `$` stop at `\r`), so heading lines fall through and render as plain paragraph text. The table parser happens to call `.trim()` on each line first — which strips the `\r` — so tables work, headings don't. The seeded `CREDITS.md` gets CRLF endings on Windows because git converts text files at checkout and the seeder copies the file byte-for-byte. Any markdown file written by a Windows editor and dropped into game assets hits the same problem. Chat messages are unaffected (typed/streamed content uses `\n`). **Fix** One-line change: split on `/\r?\n/` instead of `"\n"` so CRLF and LF input parse identically. This also protects the other line-anchored patterns in the block parser that don't trim. Related: #3240 fixed the preview's missing styles; this bug is independent of that one (the heading `#` marks survive even with styling fixed). I'm taking this one (kolacheee) — PR to `staging` incoming.
bsakaguchi 2026-10-21 05:42:11 +07:00
  • closed this issue
  • added the
    in-pr
    label
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#1742
No description provided.