Skip to content

Commit 11798ba

Browse files
committed
only add yaml blocks to metadata when they're individually objects. Closes #903
1 parent cd0d8dc commit 11798ba

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/core/yaml.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,14 @@ export function readYamlFromMarkdown(
100100
(yamlBlock.trim().length > 0)
101101
) {
102102
// surface errors immediately for invalid yaml
103-
parse(yamlBlock, { json: true, schema: QuartoJSONSchema });
104-
// add it
105-
yaml += yamlBlock;
103+
const result = parse(yamlBlock, {
104+
json: true,
105+
schema: QuartoJSONSchema,
106+
});
107+
// add it only if it's an actual block
108+
if (typeof result !== "string") {
109+
yaml += yamlBlock;
110+
}
106111
}
107112

108113
match = kRegExYAML.exec(markdown);

tests/docs/yaml/yaml-parse-dashes.qmd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "A title"
3+
---
4+
5+
## Intro
6+
7+
---
8+
9+
This will break things.
10+
11+
---
12+
13+
#### More
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* core-yaml-dashes.test.ts
3+
*
4+
* Copyright (C) 2022 by RStudio, PBC
5+
*
6+
*/
7+
8+
import * as utils from "../../utils.ts";
9+
import * as render from "../render/render.ts";
10+
11+
const input = utils.docs("yaml/yaml-parse-dashes.qmd");
12+
13+
render.testRender(input, "revealjs", false);

0 commit comments

Comments
 (0)