Documentation
¶
Overview ¶
Package kazari renders framed, syntax-highlighted HTML code blocks with full CSS customization via custom properties.
Index ¶
- Constants
- func CreateInlineSVGURL(svg string) string
- type AdjustTargets
- type AssetFile
- type Assets
- type BlockDefaults
- type BlockDefaultsFileConfig
- type CollapseOptions
- type CollapseStyle
- type CollapsibleConfig
- type CollapsibleFileConfig
- type DarkMode
- type DarkModeFileConfig
- type DualThemeTokenizer
- type Engine
- func (e *Engine) Assets() Assets
- func (e *Engine) CSS() string
- func (e *Engine) EnableCodeGroups()
- func (e *Engine) JS() string
- func (e *Engine) Render(code string, opts Options) (string, error)
- func (e *Engine) RenderWithMeta(code string, metaStr string) (string, error)
- func (e *Engine) ThemeCSS() string
- func (e *Engine) Tokenize(code string, lang string) ([][]Token, error)
- type FileConfig
- type Frame
- type Highlighter
- type InlineMarker
- type LangIconMode
- type LineMarker
- type MarkerType
- type Option
- func FileConfigToOptions(fc *FileConfig) ([]Option, error)
- func LoadConfig(path string) ([]Option, error)
- func WithCascadeLayer(name string) Option
- func WithCollapsible(c CollapsibleConfig) Option
- func WithConfigDir(dir string) Option
- func WithContentExclusion(enabled bool) Option
- func WithCopyButton(enabled bool) Option
- func WithDarkMode(dm DarkMode) Option
- func WithDataLineCount(enabled bool) Option
- func WithDefaults(d BlockDefaults) Option
- func WithFileIconResolver(f func(ext string) string) Option
- func WithFileIcons(enabled bool) Option
- func WithFileNameExtraction(enabled bool) Option
- func WithFrameDetection(enabled bool) Option
- func WithFullscreenButton(enabled bool) Option
- func WithHighlighter(hl Highlighter) Option
- func WithLanguageAliases(m map[string]string) Option
- func WithLanguageBadge(enabled bool) Option
- func WithLanguageDefaults(m map[string]BlockDefaults) Option
- func WithLanguageIconMode(mode LangIconMode) Option
- func WithLineNumbers(enabled bool) Option
- func WithLinks(enabled bool) Option
- func WithLocale(loc string) Option
- func WithMermaidPassThrough(enabled bool) Option
- func WithMinContrast(ratio float64) Option
- func WithMinify(enabled bool) Option
- func WithStyleOverrides(overrides map[string]string) Option
- func WithStyleReset(enabled bool) Option
- func WithTabWidth(n int) Option
- func WithTerminalCommentStripping(enabled bool) Option
- func WithTerminalDotStyle(style TerminalDotStyle) Option
- func WithThemeAdjustments(adj ThemeAdjustments) Option
- func WithThemeCSSRoot(selector string) Option
- func WithThemeCustomizer(f func(themeName string, colors ThemeInfo) ThemeInfo) Option
- func WithThemeToggle(enabled bool) Option
- func WithThemedScrollbars(enabled bool) Option
- func WithThemedSelectionColors(enabled bool) Option
- func WithThemedStyleOverrides(overrides map[string]StyleValue) Option
- func WithThemes(light, dark string) Option
- func WithUIStrings(overrides map[string]string) Option
- func WithWarningHandler(f func(string)) Option
- func WithWrapButton(enabled bool) Option
- type Options
- type Range
- type StyleValue
- type TerminalDotStyle
- type ThemeAdjustments
- type ThemeInfo
- type ThemesFileConfig
- type Token
Constants ¶
const ( FontStyleNone = config.FontStyleNone FontStyleItalic = config.FontStyleItalic FontStyleBold = config.FontStyleBold FontStyleUnderline = config.FontStyleUnderline FontStyleStrikethrough = config.FontStyleStrikethrough )
Font style bitmask constants.
Variables ¶
This section is empty.
Functions ¶
func CreateInlineSVGURL ¶
CreateInlineSVGURL converts SVG markup into a data:image/svg+xml URL for use in CSS custom properties (e.g. custom file icons or terminal icons). Use single quotes for SVG attributes; double quotes are percent-encoded.
Types ¶
type AdjustTargets ¶
type AdjustTargets int
AdjustTargets selects which extracted colors a ThemeAdjustments affects.
const ( AdjustBackgrounds AdjustTargets = 1 << iota // BG, SelectionBG, FoldBG AdjustForegrounds // FG, LineNumberFG )
type AssetFile ¶
type AssetFile struct {
Content string
Hash string // 8-char hex (FNV-1a)
Filename string // e.g. "kazari-a1b2c3d4.css"
}
AssetFile holds content and its hashed filename.
type BlockDefaults ¶
type BlockDefaults struct {
Wrap bool
PreserveIndent bool
HangingIndent int
LineNumbers bool
Frame Frame
}
BlockDefaults holds default block rendering properties.
type BlockDefaultsFileConfig ¶
type BlockDefaultsFileConfig struct {
Wrap *bool `yaml:"wrap" json:"wrap"`
PreserveIndent *bool `yaml:"preserveIndent" json:"preserveIndent"`
HangingIndent *int `yaml:"hangingIndent" json:"hangingIndent"`
LineNumbers *bool `yaml:"lineNumbers" json:"lineNumbers"`
Frame *string `yaml:"frame" json:"frame"`
}
type CollapseOptions ¶
type CollapseOptions struct {
Enabled bool // true = force threshold-based collapse
Disabled bool // true = force no collapse (nocollapse)
Ranges []Range // specific ranges to collapse
Style *CollapseStyle // nil = use engine default
Threshold *int // nil = use engine default; overrides engine LineThreshold for this block
}
CollapseOptions holds per-block collapse configuration.
type CollapseStyle ¶
type CollapseStyle int
CollapseStyle identifies the visual style for range-based collapsible sections.
const ( CollapseGithub CollapseStyle = iota // one-way expand, summary disappears CollapseCollapsibleStart // re-collapsible, summary above content CollapseCollapsibleEnd // re-collapsible, summary below content CollapseCollapsibleAuto // auto: end if section reaches last line, else start )
type CollapsibleConfig ¶
type CollapsibleConfig struct {
LineThreshold int
PreviewLines int
DefaultCollapsed bool
PreserveIndent bool
Style CollapseStyle
ExpandButtonText string
CollapseButtonText string
ExpandedAnnouncement string // screen reader
CollapsedAnnouncement string // screen reader
}
CollapsibleConfig configures threshold-based collapsible code blocks.
type CollapsibleFileConfig ¶
type CollapsibleFileConfig struct {
LineThreshold *int `yaml:"lineThreshold" json:"lineThreshold"`
PreviewLines *int `yaml:"previewLines" json:"previewLines"`
DefaultCollapsed *bool `yaml:"defaultCollapsed" json:"defaultCollapsed"`
PreserveIndent *bool `yaml:"preserveIndent" json:"preserveIndent"`
Style *string `yaml:"style" json:"style"`
ExpandButtonText *string `yaml:"expandButtonText" json:"expandButtonText"`
CollapseButtonText *string `yaml:"collapseButtonText" json:"collapseButtonText"`
ExpandedAnnouncement *string `yaml:"expandedAnnouncement" json:"expandedAnnouncement"`
CollapsedAnnouncement *string `yaml:"collapsedAnnouncement" json:"collapsedAnnouncement"`
}
type DarkMode ¶
type DarkMode interface {
// contains filtered or unexported methods
}
DarkMode controls how dark mode CSS is generated.
func MediaQueryMode ¶
func MediaQueryMode() DarkMode
MediaQueryMode uses prefers-color-scheme media query for dark mode.
func SelectorMode ¶
SelectorMode uses a CSS class selector for dark mode switching. Example: SelectorMode(".dark") produces :root.dark { ... }
type DarkModeFileConfig ¶
type DualThemeTokenizer ¶
type DualThemeTokenizer interface {
TokenizeDual(code, lang, lightTheme, darkTheme string) (light, dark [][]Token, err error)
}
DualThemeTokenizer is an optional capability for highlighters that can resolve two themes from a single tokenization pass. TextMate scanning is theme-independent, so a capable highlighter halves dual-theme work. The two returned streams MUST have identical token boundaries (same line count, same per-line token count and Content). The engine type-asserts this interface on its Highlighter and falls back to two Tokenize calls when it is absent.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the main entry point for rendering code blocks.
func (*Engine) EnableCodeGroups ¶
func (e *Engine) EnableCodeGroups()
EnableCodeGroups enables code group CSS/JS in engine output. Called automatically by kazarimd.CodeGroups(). It mutates the engine configuration without synchronization, so call it during setup before the engine is shared with concurrent Render, CSS, or JS callers.
func (*Engine) RenderWithMeta ¶
RenderWithMeta parses a meta string and renders the code block.
type FileConfig ¶
type FileConfig struct {
Themes *ThemesFileConfig `yaml:"themes" json:"themes"`
DarkMode *DarkModeFileConfig `yaml:"darkMode" json:"darkMode"`
CopyButton *bool `yaml:"copyButton" json:"copyButton"`
FullscreenButton *bool `yaml:"fullscreenButton" json:"fullscreenButton"`
WrapButton *bool `yaml:"wrapButton" json:"wrapButton"`
ThemeToggleButton *bool `yaml:"themeToggleButton" json:"themeToggleButton"`
LineNumbers *bool `yaml:"lineNumbers" json:"lineNumbers"`
FrameDetection *bool `yaml:"frameDetection" json:"frameDetection"`
FileNameExtraction *bool `yaml:"fileNameExtraction" json:"fileNameExtraction"`
LanguageBadge *bool `yaml:"languageBadge" json:"languageBadge"`
ThemedScrollbars *bool `yaml:"themedScrollbars" json:"themedScrollbars"`
ThemedSelection *bool `yaml:"themedSelection" json:"themedSelection"`
ContentExclusion *bool `yaml:"contentExclusion" json:"contentExclusion"`
MermaidPassThrough *bool `yaml:"mermaidPassThrough" json:"mermaidPassThrough"`
TerminalCommentStripping *bool `yaml:"terminalCommentStripping" json:"terminalCommentStripping"`
DataLineCount *bool `yaml:"dataLineCount" json:"dataLineCount"`
FileIcons *bool `yaml:"fileIcons" json:"fileIcons"`
Links *bool `yaml:"links" json:"links"`
StyleReset *bool `yaml:"styleReset" json:"styleReset"`
Minify *bool `yaml:"minify" json:"minify"`
TabWidth *int `yaml:"tabWidth" json:"tabWidth"`
MinContrast *float64 `yaml:"minContrast" json:"minContrast"`
CascadeLayer *string `yaml:"cascadeLayer" json:"cascadeLayer"`
ThemeCSSRoot *string `yaml:"themeCSSRoot" json:"themeCSSRoot"`
Locale *string `yaml:"locale" json:"locale"`
TerminalDotStyle *string `yaml:"terminalDotStyle" json:"terminalDotStyle"`
LanguageIconMode *string `yaml:"languageIconMode" json:"languageIconMode"`
Defaults *BlockDefaultsFileConfig `yaml:"defaults" json:"defaults"`
LanguageDefaults map[string]BlockDefaultsFileConfig `yaml:"languageDefaults" json:"languageDefaults"`
Collapsible *CollapsibleFileConfig `yaml:"collapsible" json:"collapsible"`
LanguageAliases map[string]string `yaml:"languageAliases" json:"languageAliases"`
UIStrings map[string]string `yaml:"uiStrings" json:"uiStrings"`
StyleOverrides map[string]any `yaml:"styleOverrides" json:"styleOverrides"`
}
FileConfig represents a Kazari configuration file (YAML or JSON). All fields use pointer types so omitted keys are distinguishable from zero values.
func ParseConfig ¶
func ParseConfig(data []byte, format string) (*FileConfig, error)
ParseConfig parses config bytes in the given format ("yaml" or "json") and validates the result.
type Highlighter ¶
type Highlighter interface {
Tokenize(code, lang, theme string) ([][]Token, error)
GetThemeColors(theme string) (ThemeInfo, error)
GetLoadedLanguages() []string
}
Highlighter abstracts syntax highlighting. The default implementation wraps Nuri, but any implementation (including mocks) can be used.
type InlineMarker ¶
type InlineMarker struct {
Type MarkerType
Text string
IsRegex bool
}
InlineMarker represents an inline text marker.
type LangIconMode ¶
type LangIconMode int
LangIconMode controls language icon display in the toolbar badge area.
const ( LangIconNone LangIconMode = iota // text label only (default) LangIconOnly // icon replaces text LangIconAndText // icon shown before text label )
type LineMarker ¶
type LineMarker struct {
Type MarkerType
Lines []Range
Label string // empty for unlabeled
}
LineMarker represents a line-level marker with optional label.
type MarkerType ¶
type MarkerType int
MarkerType identifies the kind of line or inline marker.
const ( MarkerMark MarkerType = iota // highlight (default, lowest priority) MarkerDel // deleted MarkerIns // inserted (highest priority) )
Priority order: mark(0) < del(1) < ins(2). Higher value wins in overlap resolution.
type Option ¶
type Option func(*engineBuilder)
Option configures the Engine during construction.
func FileConfigToOptions ¶
func FileConfigToOptions(fc *FileConfig) ([]Option, error)
FileConfigToOptions converts a FileConfig into a slice of functional options.
func LoadConfig ¶
LoadConfig reads a config file, detects format from extension, parses, validates, and returns functional options.
func WithCascadeLayer ¶
func WithCollapsible ¶
func WithCollapsible(c CollapsibleConfig) Option
func WithConfigDir ¶
WithConfigDir searches the given directory for a config file (kazari.config.yaml, .yml, or .json) and applies its options. If no config file is found, it is a silent no-op. Parse errors are reported via WarningHandler.
func WithContentExclusion ¶
func WithCopyButton ¶
func WithDarkMode ¶
func WithDataLineCount ¶
func WithDefaults ¶
func WithDefaults(d BlockDefaults) Option
func WithFileIconResolver ¶
func WithFileIcons ¶
func WithFileNameExtraction ¶
func WithFrameDetection ¶
func WithFullscreenButton ¶
func WithHighlighter ¶
func WithHighlighter(hl Highlighter) Option
func WithLanguageAliases ¶
func WithLanguageBadge ¶
func WithLanguageDefaults ¶
func WithLanguageDefaults(m map[string]BlockDefaults) Option
func WithLanguageIconMode ¶
func WithLanguageIconMode(mode LangIconMode) Option
func WithLineNumbers ¶
func WithLocale ¶
func WithMermaidPassThrough ¶
func WithMinContrast ¶
func WithMinify ¶
func WithStyleOverrides ¶
func WithStyleReset ¶
func WithTabWidth ¶
func WithTerminalDotStyle ¶
func WithTerminalDotStyle(style TerminalDotStyle) Option
func WithThemeAdjustments ¶
func WithThemeAdjustments(adj ThemeAdjustments) Option
WithThemeAdjustments tints the extracted theme colors in OKLCH space, applied to both themes before the theme customizer runs.
func WithThemeCSSRoot ¶
func WithThemeCustomizer ¶
func WithThemeToggle ¶
func WithThemedScrollbars ¶
func WithThemedStyleOverrides ¶
func WithThemedStyleOverrides(overrides map[string]StyleValue) Option
func WithThemes ¶
func WithUIStrings ¶
func WithWarningHandler ¶
WithWarningHandler sets the function that receives non-fatal warnings, such as unknown language fallbacks. When unset, warnings go to log.Printf. Pass a no-op function to silence warnings entirely.
func WithWrapButton ¶
type Options ¶
type Options struct {
Lang string
Title string
Theme string
Frame *Frame // nil = use default
LineNumbers *bool // nil = use default
StartLineNumber *int // nil = use default (1)
Wrap *bool // nil = use default
PreserveIndent *bool // nil = use default
HangingIndent *int // nil = use default
DiffLang string // original language for diff+syntax hybrid (e.g., "go")
LineMarkers []LineMarker
InlineMarkers []InlineMarker
FocusLines []Range
Collapse *CollapseOptions
}
Options is the per-block configuration passed to Render or derived from meta string.
type StyleValue ¶
type StyleValue struct {
Value string // used when both themes share the same value
Dark string // dark theme override
Light string // light theme override
}
StyleValue represents a CSS variable override that can be universal or per-theme.
func (StyleValue) DarkValue ¶
func (sv StyleValue) DarkValue() string
DarkValue returns the value to use for the dark theme.
func (StyleValue) IsThemed ¶
func (sv StyleValue) IsThemed() bool
IsThemed reports whether this value has per-theme overrides.
func (StyleValue) LightValue ¶
func (sv StyleValue) LightValue() string
LightValue returns the value to use for the light theme.
type TerminalDotStyle ¶
type TerminalDotStyle int
TerminalDotStyle determines how terminal frame dots are rendered.
const ( DotsColored TerminalDotStyle = iota // macOS red/yellow/green DOM spans (default) DotsMinimal // CSS-only monochrome dots via SVG mask )
type ThemeAdjustments ¶
type ThemeAdjustments struct {
Hue *float64 // target hue in degrees (0-360); nil = unchanged
Chroma *float64 // target chroma (0-0.4 typical); nil = unchanged
Targets AdjustTargets // bitmask; zero value = AdjustBackgrounds
}
ThemeAdjustments tints extracted theme colors in OKLCH space. Nil fields leave that channel unchanged. Adjustments apply to the editor colors used for CSS variables, not to individual syntax token colors.
type ThemeInfo ¶
type ThemeInfo struct {
FG string // default foreground (e.g. "#24292f")
BG string // default background (e.g. "#ffffff")
SelectionBG string // editor.selectionBackground
LineNumberFG string // editorLineNumber.foreground
FoldBG string // editor.foldBackground
}
ThemeInfo holds colors extracted from a syntax theme for CSS variable generation.
type ThemesFileConfig ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
demo
|
|
|
internal/contrastcheck
command
|
|
|
nuri
command
|
|
|
site
command
|
|
|
visualcheck
command
|
|
|
internal
|
|
|
svgutil
Package svgutil encodes inline SVG markup as CSS-safe data URLs.
|
Package svgutil encodes inline SVG markup as CSS-safe data URLs. |