Skip to content

Commit 1628450

Browse files
authored
Merge pull request #372 from marp-team/strip-utf8-bom
Strip UTF-8 BOM from Markdown
2 parents f026b01 + cb50456 commit 1628450

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
- `--pdf-notes` option to add presenter notes into PDF as annotations ([#261](https://github.com/marp-team/marp-cli/issues/261), [#369](https://github.com/marp-team/marp-cli/pull/369))
99
- `author` and `keywords` metadata options / global directives ([#367](https://github.com/marp-team/marp-cli/issues/367), [#370](https://github.com/marp-team/marp-cli/pull/370))
1010

11+
### Fixed
12+
13+
- Cannot parse front-matter if input file had UTF-8 BOM ([#357](https://github.com/marp-team/marp-cli/issues/357), [#372](https://github.com/marp-team/marp-cli/pull/372))
14+
1115
### Changed
1216

1317
- Upgrade dependent packages to the latest version ([#371](https://github.com/marp-team/marp-cli/pull/371))

src/converter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export interface ConvertResult {
8888

8989
export type ConvertedCallback = (result: ConvertResult) => void
9090

91+
const stripBOM = (s: string) => (s.charCodeAt(0) === 0xfeff ? s.slice(1) : s)
92+
9193
export class Converter {
9294
readonly options: ConverterOption
9395

@@ -149,7 +151,7 @@ export class Converter {
149151
: undefined,
150152
renderer: (tplOpts) => {
151153
const engine = this.generateEngine(tplOpts)
152-
const ret = engine.render(`${markdown}${additionals}`)
154+
const ret = engine.render(stripBOM(`${markdown}${additionals}`))
153155
const info = engine[engineInfo]
154156

155157
if (isFile(file))

test/converter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ describe('Converter', () => {
125125
expect(disabled.html).toContain('<i>Hello!</i>')
126126
})
127127

128+
it('strips UTF-8 BOM', async () => {
129+
const noBOM = await instance().convert('---\ntitle: test\n---')
130+
const BOM = await instance().convert('\ufeff---\ntitle: test\n---')
131+
132+
expect(BOM.result).toStrictEqual(noBOM.result)
133+
expect(BOM.rendered.title).toBe('test')
134+
})
135+
128136
describe('with globalDirectives option', () => {
129137
it('overrides theme directive', async () => {
130138
const { rendered } = await instance({

0 commit comments

Comments
 (0)