parser

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package parser parses Markdown content and YAML Front Matter into Article structs.

Package parser parses Markdown content and YAML Front Matter from content files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

Converter converts Markdown source bytes into safe HTML. It is CommonMark-compliant and supports GitHub Flavored Markdown (GFM) extensions by default.

func NewConverter

func NewConverter(opts ...ConverterOption) *Converter

NewConverter builds a Converter with the supplied options. When no options are given, GFM extensions are enabled and raw HTML is escaped.

func (*Converter) Convert

func (c *Converter) Convert(src []byte) (template.HTML, error)

Convert transforms src Markdown bytes into an HTML string. The returned value is marked safe for use with html/template without additional escaping.

type ConverterOption

type ConverterOption func(*converterConfig)

ConverterOption is a functional option for NewConverter.

func WithGFM

func WithGFM() ConverterOption

WithGFM enables the GitHub Flavored Markdown extension set (tables, strikethrough, task lists, and auto-links). Enabled by default via NewConverter.

func WithHighlighting

func WithHighlighting(cfg highlight.Config) ConverterOption

WithHighlighting enables chroma syntax highlighting for fenced code blocks. cfg specifies the chroma theme and line-number settings.

func WithMermaid

func WithMermaid() ConverterOption

WithMermaid enables client-side Mermaid diagram rendering. Fenced code blocks tagged "mermaid" are output as <div class="mermaid">.

func WithUnsafeHTML

func WithUnsafeHTML() ConverterOption

WithUnsafeHTML allows raw HTML pass-through in Markdown source. By default raw HTML is escaped. Use only when the content source is trusted.

type FileParser

type FileParser struct {
	// contains filtered or unexported fields
}

FileParser implements the Parser interface, reading Markdown files from disk. Each file may optionally begin with a YAML front matter block delimited by "---" lines. The remainder of the file is treated as the raw Markdown body.

ExcludeFiles holds glob patterns (relative to the content directory) that should be skipped during ParseAll. Patterns use filepath.Match syntax.

func NewFileParser

func NewFileParser(excludeFiles ...string) *FileParser

NewFileParser returns a new FileParser. Pass any number of glob patterns (relative to the content directory) to exclude matching files from ParseAll.

func (*FileParser) Parse

func (p *FileParser) Parse(filePath string) (*model.Article, error)

Parse reads the file at filePath, extracts any YAML front matter, and returns a fully populated *model.Article.

func (*FileParser) ParseAll

func (p *FileParser) ParseAll(contentDir string) ([]*model.Article, error)

ParseAll walks contentDir recursively and returns one *model.Article per Markdown file (.md or .markdown extension, case-insensitive). Files whose path (relative to contentDir) matches any pattern in FileParser.excludeFiles are silently skipped.

type Parser

type Parser interface {
	// Parse reads the file at filePath and returns a fully populated Article.
	Parse(filePath string) (*model.Article, error)

	// ParseAll walks contentDir and returns one Article per Markdown file found.
	ParseAll(contentDir string) ([]*model.Article, error)
}

Parser converts a raw Markdown file (with optional YAML front matter) into a model.Article ready for further processing.

Jump to

Keyboard shortcuts

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