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
5 changes: 5 additions & 0 deletions .changeset/tidy-headings-match.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@design-intelligence/ghost": patch
---

Resolve check heading anchors against Markdown headings with optional closing hashes.
6 changes: 5 additions & 1 deletion packages/ghost/src/ghost-core/check/source-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export function sliceNodeSection(body: string, heading: string): string | null {
let level = 0;
for (let i = 0; i < lines.length; i += 1) {
const match = headingPattern.exec(lines[i]);
if (match && match[2].trim().toLowerCase() === wanted) {
const headingText = match?.[2]
.replace(/[ \t]+#+[ \t]*$/, "")
.trim()
.toLowerCase();
if (match && headingText === wanted) {
startLine = i;
level = match[1].length;
break;
Expand Down
10 changes: 10 additions & 0 deletions packages/ghost/test/ghost-core/source-ref.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ Other prose.
);
});

it("matches headings with optional closing hashes", () => {
const body = "## Confirmation ##\n\nConfirmation prose.\n";
expect(sliceNodeSection(body, "Confirmation")).toBe("Confirmation prose.");
});

it("preserves hashes that are part of the heading text", () => {
const body = "## Confirm #1\n\nFirst confirmation.\n";
expect(sliceNodeSection(body, "Confirm #1")).toBe("First confirmation.");
});

it("stops at the next heading of the same level", () => {
const slice = sliceNodeSection(BODY, "Confirmation");
expect(slice).not.toContain("Next Section");
Expand Down
Loading