Skip to content

fix(tagging): split frontmatter with the same fence rule the index uses - #75

Open
Abhishek-B-R wants to merge 1 commit into
AlmanacCode:mainfrom
Abhishek-B-R:fix/frontmatter-fence-rewrite
Open

Abhishek-B-R wants to merge 1 commit into
AlmanacCode:mainfrom
Abhishek-B-R:fix/frontmatter-fence-rewrite

Conversation

@Abhishek-B-R

@Abhishek-B-R Abhishek-B-R commented Oct 1, 2026 •

Copy link
Copy Markdown

Summary

  • split_frontmatter now splits line by line on the same fence rule python-frontmatter uses (-{3,} plus optional trailing whitespace), and takes the line ending from the opening fence.
  • two regression tests in tests/test_tagging.py.

Why

tag/untag and topic rename find frontmatter with a literal ---\n opener and a \n--- search that starts after it, but the index parses pages with python-frontmatter. when the two disagree, the rewrite prepends a second block and leaves the old one in the body.

repro: a page that starts ---\n---\n# Note, then codealmanac tag note concepts. the file ends up as ---\ntopics:\n- concepts\n---\n---\n---\n# Note. same thing when the opening fence has trailing spaces. topics rename / delete also skip those pages since they read no topics.

Verification

uv run pytest            # 566 passed
uv run ruff check .      # clean
git diff --check

Docs and wiki

  • README/docs updated if user-facing behavior changed.
  • .almanac/ wiki updated if an implementation decision, workflow, invariant, or gotcha changed.
  • Not applicable.

both new tests fail on main and pass here.

Notes for reviewers

a page whose first line is a ---- thematic break is now read as a frontmatter opener by the rewriter. that is what the index already does, so the two stay consistent.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Topic rewrites found the frontmatter block with a literal "---\n" /
"\n---" search, while the index parses pages with python-frontmatter,
which accepts any run of three or more dashes with trailing whitespace.
When the two disagreed, tag/untag saw no frontmatter and prepended a new
block, leaving the old one in the body, and topic rename/delete read no
topics from the page and skipped it:

- an empty block (---/---) was never recognised, because the closer
  search started past it
- a fence with trailing spaces was skipped, so tagging left the page with
  two frontmatter blocks and the index lost its title

Split line by line on the shared fence rule instead, and take the line
ending from the opening fence.

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