Skip to content

fix(parser): ignore a leading UTF-8 BOM - #2802

Open
b84330808 wants to merge 1 commit into
slidevjs:mainfrom
b84330808:fix-parser-bom
Open

b84330808 wants to merge 1 commit into
slidevjs:mainfrom
b84330808:fix-parser-bom

Conversation

@b84330808

Copy link
Copy Markdown

Bug

If slides.md is saved with a UTF-8 byte order mark, the headmatter is ignored. The first line is ---, which doesn't start with ---, so the parser doesn't see a frontmatter block:

---
theme: seriph
title: Hello
---

# Slide 1

---

# Slide 2

Saved with a BOM, parse() returns 3 slides instead of 2. The first slide has empty frontmatter and its content is ---\ntheme: seriph\ntitle: Hello, so the theme, title and other deck config are lost and an extra slide with the raw YAML is shown. load() has the same problem when it looks for the headmatter to load preparser extensions.

Editors and tools that write "UTF-8 with BOM" (Notepad's "UTF-8 with BOM" option, Visual Studio, PowerShell 5.1 Set-Content -Encoding UTF8) produce such files, mostly on Windows.

Fix

  • parse() and parseSync() drop a leading BOM before splitting the lines.
  • RE_FRONTMATTER_START in fs.ts allows an optional BOM before ---.

Tests

Added ignores a leading UTF-8 BOM to test/parser.test.ts. It checks the slides and frontmatter from parse() and the headmatter from load(). It fails without the change and passes with it.

I used Claude Code to write this change.

A slides.md saved with a BOM starts with "\uFEFF---", so the headmatter
was not recognized: the deck config was dropped and its YAML became an
extra first slide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for slidev ready!

Name Link
🔨 Latest commit b862407
🔍 Latest deploy log https://app.netlify.com/projects/slidev/deploys/6ae0630f1bdce5bbd16535ea
😎 Deploy Preview https://deploy-preview-2802--slidev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

This branch has not been deployed

No deployments
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.

1 participant