Commit b2a4775
authored
fix(compiler): preserve frontmatter when closing "---" has no trailing newline (#121)
* fix(compiler): preserve frontmatter when closing "---" has no trailing newline
`frontmatter.split` returns the frontmatter block ending in a bare "\n---"
(not "\n---\n") for a page that ends right at the closing delimiter with no
trailing newline — e.g. a frontmatter-only concept/entity page. Both
`_prepend_source_to_frontmatter` and `_remove_source_from_frontmatter` located
the closing delimiter with `fm_block.rpartition("\n---\n")`, which finds
nothing in that case: `fm_prefix` becomes "" and every existing frontmatter
line (the opening "---", `type`, `description`, and the prior `sources:` list)
is dropped — silently corrupting the page and losing source provenance.
Strip whichever closing form is actually present ("\n---\n" or a bare "\n---")
and re-append the same one. Pages that have a body (the common case) are
byte-for-byte unaffected.
This is reached in practice via `_add_related_link` (run for every related
concept/entity during compile) and the `openkb remove` flow
(`remove_doc_from_{concept,entity}_pages`).
Adds `TestFrontmatterSourceMutation` covering prepend + remove on a
no-trailing-newline page, plus a with-body regression guard.
* test: fix docstring referencing _prepend (now _prepend_source_to_frontmatter)1 parent 3fea8cf commit b2a4775
2 files changed
Lines changed: 46 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
951 | 951 | | |
952 | 952 | | |
953 | 953 | | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
958 | 962 | | |
959 | | - | |
960 | 963 | | |
961 | 964 | | |
962 | 965 | | |
| |||
992 | 995 | | |
993 | 996 | | |
994 | 997 | | |
995 | | - | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
996 | 1003 | | |
997 | | - | |
998 | 1004 | | |
999 | 1005 | | |
1000 | 1006 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
35 | 68 | | |
36 | 69 | | |
37 | 70 | | |
| |||
0 commit comments