doc

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package doc는 마크다운 문서 하나를 프론트매터와 본문으로 가르고 프론트매터를 YAML로 파싱하고 본문에서 위키링크를 추출한다. 필드 검증은 lint 쪽 책임이고 여기는 파싱까지다.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(fields []Field, body string) []byte

Render는 파싱의 역연산으로 필드와 본문을 문서 바이트로 만든다. 필드 순서는 입력 순서를 그대로 쓴다. 필드가 없으면 프론트매터 구분자를 내지 않는다. 줄바꿈은 LF이고 본문 끝에는 개행 하나를 보장한다.

func RenderMap

func RenderMap(fm map[string]any, body string) []byte

RenderMap은 프론트매터 맵과 본문으로 문서 바이트를 만든다. 키 순서는 StandardKeys의 표준 순서이고 표준에 없는 키는 이름순으로 뒤에 붙는다. 값은 문자열, 불리언, []string, nil(빈 값 키)을 받는다.

func StandardKeys

func StandardKeys() []string

StandardKeys는 새 문서의 프론트매터 키 표준 순서다. 파싱이 키 순서를 보존하므로 직렬화도 순서를 그대로 쓰며, 기준 순서가 없는 새 문서는 이 순서를 따른다. ADR 0005가 프론트매터 정규화를 parity 비교 축으로 삼으므로 직렬화 순서는 언제나 결정론적이어야 한다.

Types

type Doc

type Doc struct {
	Path           string
	HasFrontmatter bool
	Fields         []Field
	Body           string
	BodyLine       int // 본문 첫 줄의 원본 파일 줄 번호 (1 기반)
	// contains filtered or unexported fields
}

Doc는 문서 하나의 파싱 결과다.

func Parse

func Parse(path string, content []byte) (Doc, error)

Parse는 문서 원문을 프론트매터와 본문으로 가른 뒤 프론트매터를 파싱한다. 프론트매터가 없는 문서도 정상 입력이며 이때 Body는 원문 전체고 BodyLine은 1이다.

func (d Doc) BodyLinks() []Link

BodyLinks는 본문에서 링크를 순서대로 추출한다. 코드 펜스(```)와 인라인 코드(백틱) 안의 것은 링크가 아니다. 문서에 링크 문법 자체를 설명해도 판정이 틀어지지 않게 하기 위해서다.

func (d Doc) FrontmatterLinks() []Link

FrontmatterLinks는 프론트매터 related 필드의 링크를 반환한다. 링크 문법을 설명하는 문서에서 게이트가 셀 링크를 본문 것과 섞지 않도록 본문과 분리했다.

type Field

type Field struct {
	Key  string
	Kind ValueKind
	Str  string   // KindString, KindDate
	List []string // KindStringList
	Bool bool     // KindBool
}

Field는 프론트매터 키 하나의 파싱 결과다. 원본에 나온 순서를 유지한다.

type Link struct {
	Slug string
	Line int // 원본 파일 기준 1 기반 줄 번호
}

Link는 추출된 링크 하나다. 중복 제거는 하지 않는다. 세는 것은 호출자 몫이다.

type ValueKind

type ValueKind int

ValueKind는 프론트매터 값의 종류를 구분한다.

const (
	KindEmpty ValueKind = iota // 값이 없는 키 (source_channel: 처럼)
	KindString
	KindStringList
	KindBool
	KindDate // 날짜 형식의 문자열
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL