Documentation
¶
Overview ¶
Package typst provides a Markdown-to-Typst converter and Typst PDF generator.
Index ¶
- func ConvertMarginToTypst(margin string, defaultVal string) string
- type Generator
- type GeneratorOption
- func WithAuthor(author string) GeneratorOption
- func WithFontFamily(family string) GeneratorOption
- func WithFontSize(size string) GeneratorOption
- func WithLanguage(lang string) GeneratorOption
- func WithLineHeight(h float64) GeneratorOption
- func WithMargins(left, right, top, bottom string) GeneratorOption
- func WithPageSize(size string) GeneratorOption
- func WithTimeout(d time.Duration) GeneratorOption
- func WithTitle(title string) GeneratorOption
- func WithVersion(version string) GeneratorOption
- type MarkdownToTypstConverter
- type TypstTemplateData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertMarginToTypst ¶
ConvertMarginToTypst converts a margin value (e.g., "20mm", "1in") to a Typst string. If the value is empty, returns a default value. The value is sanitized to prevent Typst code injection.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator converts HTML/Markdown content to PDF using Typst.
func NewGenerator ¶
func NewGenerator(opts ...GeneratorOption) *Generator
NewGenerator creates a Typst PDF generator.
type GeneratorOption ¶
type GeneratorOption func(*Generator)
GeneratorOption customizes a Typst generator.
func WithAuthor ¶
func WithAuthor(author string) GeneratorOption
WithAuthor sets the document author.
func WithFontFamily ¶
func WithFontFamily(family string) GeneratorOption
WithFontFamily sets the font family.
func WithLanguage ¶
func WithLanguage(lang string) GeneratorOption
WithLanguage sets the document language.
func WithLineHeight ¶
func WithLineHeight(h float64) GeneratorOption
WithLineHeight sets the line height.
func WithMargins ¶
func WithMargins(left, right, top, bottom string) GeneratorOption
WithMargins sets page margins.
func WithPageSize ¶
func WithPageSize(size string) GeneratorOption
WithPageSize sets the page size (e.g., "A4", "Letter").
func WithTimeout ¶
func WithTimeout(d time.Duration) GeneratorOption
WithTimeout sets the operation timeout.
func WithVersion ¶
func WithVersion(version string) GeneratorOption
WithVersion sets the document version.
type MarkdownToTypstConverter ¶
type MarkdownToTypstConverter struct {
}
MarkdownToTypstConverter converts Markdown syntax to Typst syntax. Typst syntax is quite close to Markdown, with some key differences:
- `# Heading` → `= Heading`
- `**bold**` → `*bold*`
- `*italic*` → `_italic_`
- “ `code` “ → “ `code` “
- ```code blocks``` → ``` ```code blocks``` ``` (block syntax)
- `` → `#image("img")`
- `[text](url)` → `#link("url")[text]`
func (*MarkdownToTypstConverter) Convert ¶
func (c *MarkdownToTypstConverter) Convert(markdown string) string
Convert takes Markdown text and converts it to Typst markup.
type TypstTemplateData ¶
type TypstTemplateData struct {
Title string
Subtitle string
Author string
Date string
Version string
Language string
Content string // The Typst-formatted body content
PageWidth string // e.g., "210mm" for A4
PageHeight string // e.g., "297mm"
MarginTop string
MarginRight string
MarginBottom string
MarginLeft string
FontFamily string
FontSize string
LineHeight float64
}
TypstTemplateData holds the data needed to render a Typst document.