Skip to content

Commit 18af6f1

Browse files
committed
fix: preserve intro content when injecting YAML (body after Quarto header only)
Made-with: Cursor
1 parent 5de34e3 commit 18af6f1

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

scripts/inject-qmd-yaml-into-md.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,21 @@ def extract_yaml_from_qmd(path: Path) -> str:
4444

4545

4646
def extract_body_from_quartos_md(text: str) -> str:
47-
"""Return the body of the doc (from first ## heading to end). Quarto GFM
48-
outputs: # Title\nAuthor\nDate\n\n## First section..."""
47+
"""Return the body of the doc. Quarto GFM outputs:
48+
# Title\nAuthor\nDate\n\nintro...\n\n## Section...
49+
We skip the first # line and author/date until a blank line, then keep the rest."""
4950
lines = text.splitlines()
50-
for i, line in enumerate(lines):
51-
if line.strip().startswith("##"):
52-
return "\n".join(lines[i:])
53-
return "\n".join(lines)
51+
i = 0
52+
# Skip first line if it's a single # title
53+
if lines and lines[0].strip().startswith("# ") and not lines[0].strip().startswith("##"):
54+
i = 1
55+
# Skip author/date lines until blank line
56+
while i < len(lines) and lines[i].strip() != "":
57+
i += 1
58+
# Skip the blank line
59+
if i < len(lines) and lines[i].strip() == "":
60+
i += 1
61+
return "\n".join(lines[i:]) if i < len(lines) else ""
5462

5563

5664
def process_post_dir(dir_path: Path) -> None:

0 commit comments

Comments
 (0)