lexical

package
v1.801.469 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

func Build(blocks []Block) string

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

func FromHTML(fragment string) string

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

func FromMarkdown(md string) string

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.

func FromPlain

func FromPlain(text string) string

FromPlain renders plain text: blank-line-separated paragraphs, each preserving its interior line breaks. It is the identity-preserving path for content with no markup (Evernote plain notes, a raw text import).

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

func MarkdownBlocks(md string) []Block

MarkdownBlocks is the block parser behind FromMarkdown, exported so a normalizer that first rewrites links (Notion) can reuse the SAME block model.

Jump to

Keyboard shortcuts

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