Documentation
¶
Overview ¶
Package lexical builds a Lexical EditorState JSON string from block-structured content. It is the ONE place a KB importer turns markdown / HTML / plain text into the kb-page `body` shape the console's Lexical editor renders and the KB indexer flattens (clients/knowledge.lexicalText is the inverse reader).
It is pure (no cloud, no I/O). Inline content — including "[[wikilinks]]" — is carried VERBATIM as text so link extraction sees exactly what the author wrote; this package deliberately does NOT parse inline marks (bold/italic/inline links) into Lexical formatting, keeping the conversion honest at block granularity.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build renders blocks to a Lexical EditorState JSON string. An empty block set yields a valid document with a single empty paragraph, so the editor always loads a well-formed state.
func FromHTML ¶
FromHTML parses an HTML fragment/document at block granularity, emitting a block per block-level element (h1-h6, p, blockquote, pre, li) in document order and grouping consecutive <li> under a list block. Inline text is collected verbatim with <br> as a newline; anchor text is kept (a normalizer that needs the href rewrites it to "[[Title]]" before calling this). Malformed HTML degrades to the text it can recover rather than failing.
func FromMarkdown ¶
FromMarkdown parses markdown at BLOCK granularity — headings, fenced code, blockquotes, bullet/number lists, and paragraphs — keeping inline content verbatim (so "[[wikilinks]]" and other inline syntax survive untouched). It does not parse inline emphasis or inline links into Lexical marks.
Types ¶
type Block ¶
type Block struct {
Type string // "paragraph" | "heading" | "quote" | "code"
Tag string // heading level: "h1".."h6" (heading only)
Text string // inline text (paragraph/heading/quote/code)
List string // "bullet" | "number" — set to render Items as a list block
Items []string // list rows (when List is set)
}
Block is one block-level unit of a document. Text holds the block's inline text (newlines become Lexical linebreak nodes); Items holds a list's rows. The zero value is an empty paragraph.
func MarkdownBlocks ¶
MarkdownBlocks is the block parser behind FromMarkdown, exported so a normalizer that first rewrites links (Notion) can reuse the SAME block model.