Documentation
¶
Index ¶
- func BuildAsideJSX(ad *AsideSegment) string
- func BuildCodeJSX(lang, code string) string
- func DirectiveComponents(src string) []string
- func ExtractImports(src string) []string
- func HTMLToJSX(html string) string
- func HasAsideSegments(segments []MDXSegment) bool
- func HasCodeSegments(segments []MDXSegment) bool
- func RenderSegmentsToHTML(segments []MDXSegment) string
- func RenderToHTML(src string, cfg Config) string
- type AsideSegment
- type CodeSegment
- type Config
- type JSXBlock
- type MDXResult
- type MDXSegment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAsideJSX ¶
func BuildAsideJSX(ad *AsideSegment) string
BuildAsideJSX renders an admonition as an <Aside> component JSX string. The rendered markdown body is passed as a dangerouslySetInnerHTML div so it is emitted as raw HTML (unescaped) inside the Aside.
func BuildCodeJSX ¶
BuildCodeJSX renders a fenced code block as a <Code> component JSX string, passing the raw code as template-literal children so build-time chroma highlighting and the client-side copy/header UI both apply.
func DirectiveComponents ¶ added in v0.4.0
DirectiveComponents returns the @krate/components names used by built-in container directives in src, so the docs plugin can auto-import them.
func ExtractImports ¶
ExtractImports pulls import statements from MDX/TSX source lines. Returns only lines that start with "import " (after trimming whitespace).
func HTMLToJSX ¶
HTMLToJSX converts rendered HTML to JSX-compatible syntax. Specifically converts void elements to self-closing tags.
func HasAsideSegments ¶
func HasAsideSegments(segments []MDXSegment) bool
HasAsideSegments reports whether any segment is an <Aside> block (used to decide whether to auto-import the Aside component).
func HasCodeSegments ¶
func HasCodeSegments(segments []MDXSegment) bool
HasCodeSegments reports whether any segment is a <Code> block (used to decide whether to auto-import the Code component).
func RenderSegmentsToHTML ¶
func RenderSegmentsToHTML(segments []MDXSegment) string
RenderSegmentsToHTML renders parsed segments back into a single HTML string, suitable for a search index or prerendered fallback content. Code blocks render as plain <pre>, and admonitions as <aside>-structure markup matching the <Aside> component (without client-side icons).
func RenderToHTML ¶
RenderToHTML converts Markdown source to HTML using the given config.
Types ¶
type AsideSegment ¶
type AsideSegment struct {
Type string // admonition type: note | tip | warning | danger | caution
Title string // resolved title (Note, Tip, ...) passed explicitly
InnerHTML string // rendered markdown for the admonition body
}
AsideSegment holds an admonition (:::type ... :::) captured from markdown so it can be rendered as the <Aside> component instead of Go-generated markup.
type CodeSegment ¶
type CodeSegment struct {
Lang string // fenced code block language (may be empty)
Code string // raw code content
}
CodeSegment holds a fenced code block captured from markdown so it can be rendered as the <Code> component (with copy button + header) instead of a plain static <pre>.
type Config ¶
type Config struct {
Root string `json:"root"` // root directory of the project, used for resolving relative paths
GFM bool `json:"gfm"` // GitHub Flavored Markdown (tables, task lists, strikethrough)
HeadingAnchors bool `json:"headingAnchors"` // auto-generate id attributes on headings
Admonitions bool `json:"admonitions"` // :::note, :::tip, :::warning, :::danger
CodeHighlight bool `json:"codeHighlight"` // syntax highlighting for code blocks
CodeTheme string `json:"codeTheme"` // chroma theme name for syntax highlighting (default: github-dark)
Math bool `json:"math"` // $...$ and $$...$$ math support
Mermaid bool `json:"mermaid"` // render “`mermaid blocks as Mermaid diagrams
}
func DefaultConfig ¶
func DefaultConfig() Config
type JSXBlock ¶
type JSXBlock struct {
Index int // position in the output order
Tag string // component name
Attrs string // raw attributes string
Children string // content between opening and closing tags
}
JSXBlock represents a JSX component embedded in MDX content.
type MDXSegment ¶
type MDXSegment struct {
HTML string // rendered HTML for markdown parts
JSX string // JSX source for JSX blocks (e.g., "<CustomComponent>test</CustomComponent>")
Code *CodeSegment // fenced code block, rendered as <Code> component
Aside *AsideSegment // admonition (:::note), rendered as <Aside> component
}
MDXSegment represents either HTML text, a JSX block, or a code block for TSX generation.
func ParseMDXSegments ¶
func ParseMDXSegments(src string, cfg Config) (frontmatter map[string]any, segments []MDXSegment)
ParseMDXSegments parses MDX (or plain Markdown) and returns ordered segments (HTML + JSX blocks + code blocks) suitable for generating TSX source code. JSX blocks are returned as raw JSX strings, and fenced code blocks are returned as Code segments that render the <Code> component - both are embedded directly in TSX output.