mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-25 17:45:53 +01:00
fix(markdown): respect fenced block closers
This commit is contained in:
1 parent
8f84a23aa5
commit
945b4102f3
2 files changed
+11
-2
No files matched your search
@@ -62,6 +62,11 @@ describe("normalizeMidLineHeadings", () => {
|
||||
expect(normalizeMidLineHeadings(body)).toBe(body);
|
||||
});
|
||||
|
||||
it("does not close a fence marker that has trailing content", () => {
|
||||
const body = "```markdown\n``` still code\ncode ## comment\n```";
|
||||
expect(normalizeMidLineHeadings(body)).toBe(body);
|
||||
});
|
||||
|
||||
it("is a no-op when there is no `#` at all", () => {
|
||||
const body = "Just some prose with no markers.";
|
||||
expect(normalizeMidLineHeadings(body)).toBe(body);
|
||||
|
||||
@@ -7,7 +7,7 @@ export function normalizeEscapedLineBreaks(value: string): string {
|
||||
.replace(/\\r/g, "\n");
|
||||
}
|
||||
|
||||
const FENCE_LINE = /^(\s{0,3})(```+|~~~+)/;
|
||||
const FENCE_LINE = /^(\s{0,3})(```+|~~~+)(.*)$/;
|
||||
// A mid-line ATX heading marker: 1–6 `#`, a space, then heading text. The
|
||||
// capture keeps the char immediately before the run so we can tell a real
|
||||
// (collapsed) heading from an inline `#` token like `C#`/`F#`.
|
||||
@@ -53,7 +53,11 @@ export function normalizeMidLineHeadings(value: string): string {
|
||||
inFence = true;
|
||||
fenceChar = marker[0]!;
|
||||
fenceLength = marker.length;
|
||||
} else if (marker[0] === fenceChar && marker.length >= fenceLength) {
|
||||
} else if (
|
||||
marker[0] === fenceChar
|
||||
&& marker.length >= fenceLength
|
||||
&& fenceMatch[3]!.trim().length === 0
|
||||
) {
|
||||
inFence = false;
|
||||
fenceChar = "";
|
||||
fenceLength = 0;
|
||||
|
||||
Reference in new issue
Block a user