Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/specify_cli/markdown_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def replace_section(
offset += len(line)
text = line.rstrip("\r\n")
if metadata:
if number > 1 and text == "---":
if number > 1 and re.fullmatch(r"---[ \t]*", text):
metadata = False
continue
if fence_marker:
Expand Down
25 changes: 25 additions & 0 deletions tests/test_markdown_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,31 @@ def test_preserves_everything_outside_body(
) == expected


@pytest.mark.parametrize("closing", ["---", "--- ", "---\t"])
def test_front_matter_end_with_trailing_whitespace(closing: str) -> None:
front = "---\ndescription: |\n ## Target\n" + closing + "\n"
body = "\n# Doc\n## Target\nold\n## Next\nkeep\n"
assert replace_section(
front + body, "new\n", "target",
preset="team", contribution="body.md", artifact="spec-template",
) == front + "\n# Doc\n## Target\nnew\n## Next\nkeep\n"


@pytest.mark.parametrize("closing", ["---- ", "--- text"])
def test_front_matter_end_rejects_non_delimiter_lines(closing: str) -> None:
front = "---\ndescription: |\n ## Target\n" + closing + "\n"
body = "\n# Doc\n## Target\nold\n## Next\nkeep\n"
with pytest.raises(SectionReplacementError) as caught:
replace_section(
front + body, "new\n", "target",
preset="team", contribution="body.md", artifact="spec-template",
)
details = caught.value.details
assert details["code"] == "SECTION_NOT_FOUND"
assert details["match_count"] == 0
assert details["candidates"] == []


@pytest.mark.parametrize(
"content,replacement,expected",
[
Expand Down
Loading