LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
fix: harden frontmatter fence sanitization
nash_sua75e86675821
diff --git a/src/lib/ingest-sanitize.test.ts b/src/lib/ingest-sanitize.test.tsindex 7b6c9e65..21af1814 100644--- a/src/lib/ingest-sanitize.test.ts+++ b/src/lib/ingest-sanitize.test.ts@@ -35,6 +35,16 @@ describe("sanitizeIngestedFileContent", () => {expect(sanitizeIngestedFileContent(input)).toBe("---\ntype: x\n---\n\n# Body")})+ it("strips a frontmatter fence after leading blank lines with a case-insensitive label", () => {+ const input = "\n \n```YAML\n---\ntype: x\n---\n```\n# Body"+ expect(sanitizeIngestedFileContent(input)).toBe("---\ntype: x\n---\n# Body")+ })++ it("strips a CRLF fence around empty frontmatter", () => {+ const input = "```yaml\r\n---\r\n---\r\n```\r\n\r\n# Body"+ expect(sanitizeIngestedFileContent(input)).toBe("---\r\n---\r\n\r\n# Body")+ })+it("does NOT strip a non-fence-wrapped document containing a fenced code block in the body", () => {const input ="---\ntype: x\n---\n\n# Heading\n\n```js\nconsole.log('hi')\n```\n\nmore body"diff --git a/src/lib/ingest-sanitize.ts b/src/lib/ingest-sanitize.tsindex 03829c10..85450cb8 100644--- a/src/lib/ingest-sanitize.ts+++ b/src/lib/ingest-sanitize.ts@@ -90,7 +90,9 @@ export function sanitizeIngestedFileContent(content: string): string {/** Top-level fence wrapper. Removes the open + matching close fence lines. */function stripOuterCodeFence(content: string): string {- const open = content.match(/^[ \t]*```(?:yaml|md|markdown)?[ \t]*\r?\n/)+ const open = content.match(+ /^(?:\uFEFF)?(?:[ \t]*\r?\n)*[ \t]*```(?:yaml|md|markdown)?[ \t]*\r?\n/i,+ )if (!open) return contentconst afterOpen = content.slice(open[0].length)@@ -103,7 +105,7 @@ function stripOuterCodeFence(content: string): string {// continue with an unfenced Markdown body. Only strip this shape when// the fenced section is exactly a complete `---` frontmatter block.const frontmatterOnly = afterOpen.match(- /^(---[ \t]*\r?\n[\s\S]*?\r?\n---[ \t]*\r?\n)[ \t]*```[ \t]*(?:\r?\n|$)/,+ /^(---[ \t]*\r?\n[\s\S]*?^---[ \t]*\r?\n)[ \t]*```[ \t]*(?:\r?\n|$)/m,)if (!frontmatterOnly) return contentreturn frontmatterOnly[1] + afterOpen.slice(frontmatterOnly[0].length)