Markdown Parser

마크다운 원본을 파싱하여 WikiPageMeta를 생성하는 모듈. 파이프라인의 첫 단계로서 모든 후속 처리(전처리, 렌더링, 그래프 구축)의 입력을 준비한다.

Frontmatter 분리

splitFrontmatter--- 구분자로 YAML frontmatter와 본문을 분리한다. Frontmatter에는 제목, 문서 타입, aliases 등 메타데이터가 담기며, frontmatter가 없으면 전체가 본문이 된다.

inputexpected
--- title: Hello --- Body
title: Hello
inputexpected
--- title: Hello --- Body
Body
No frontmatter
No frontmatter

ToC 추출

extractToc은 마크다운의 H2 이하 헤딩을 추출하여 목차를 생성한다. 코드 블록 안의 헤딩은 무시한다 — 코드 예시에 포함된 ##이 목차에 나타나면 안 되기 때문이다.

H2 이하 헤딩 추출, 코드 블록 내 헤딩 제외
import { extractToc } from './src/lib/markdown/parser.ts' const toc = extractToc("## First\n### Nested\n```\n## Not\n```\n## Second") console.log(JSON.stringify({ count: toc.length, entries: toc.map(e => e.level + ':' + e.text), }))
tocResult={"count":3,"entries":["2:First","3:Nested","2:Second"]}
exprexpected
.count
3
.entries[0]
2:First
.entries[1]
3:Nested
.entries[2]
2:Second

parseMeta

parseMeta는 pagename과 원본 마크다운으로부터 전체 메타데이터를 생성한다. title은 frontmatter에서, brief는 본문 첫 문단에서 추출하되 wikilink와 외부 링크의 마크다운 문법은 제거하고 표시 텍스트만 남긴다. 이 brief가 검색 결과와 related links의 미리보기 텍스트로 사용된다.

pagenamerawexpected
test/page
--- title: Test Page --- First paragraph. ## Section
Test Page
pagenamerawexpected
test/page
--- title: T --- First paragraph.
First paragraph.
t
--- title: T --- [[Foo|표시텍스트]]는 좋다. [외부](http://ex.com)도.
표시텍스트는 좋다. 외부도.

private 디렉토리 규칙

private/ 디렉토리 하위의 문서는 자동으로 private으로 처리된다. frontmatter에 private: true가 없더라도 경로만으로 비공개 문서가 된다.

pagenamerawexpected
private/secret
--- title: Secret --- Hidden.
true