XMarkdown.API provides the core compilation interface for converting XMarkdown (SMarkdown) source text into renderable elm-ui Elements.
The API follows a two-step workflow:
CompilerOutput using compileOutputviewBodyOnly or viewTOCThis separation allows you to compile once and render different parts (body, table of contents) independently, which is useful for building rich document viewers with navigation panels.
Render only the body content from a CompilerOutput.
Takes a width parameter (in pixels) and returns a list of elm-ui Elements representing the document body without the title or banner.
bodyElements =
viewBodyOnly 600 outputThis is useful when you want to display the main content separately from other document parts like the table of contents or title.
Render the table of contents from a CompilerOutput.
Generates a navigable table of contents based on the document structure (sections, subsections, etc.).
tocElements =
viewTOC outputThe table of contents automatically includes links to document sections and respects the document hierarchy.
Re-export BlockMatch type for searching
Search blocks in the document for text containing the search query.
Returns a list of matching blocks with their metadata (id, lineNumber, numberOfLines, sourceText). The search is case-insensitive.
matches =
searchBlocksContainingText params (String.lines sourceText) "hello"import XMarkdown.API
import XMarkdown.Types exposing (defaultCompilerParameters)
-- Configure compiler
params =
{ defaultCompilerParameters
| docWidth = 600
, editCount = 0
}
-- Compile source text
output =
XMarkdown.API.compileOutput params
[ "# Introduction"
, "This is a document with **bold** text."
, ""
, "## Details"
, "More content here."
]
-- Render the document body
bodyElements =
XMarkdown.API.viewBodyOnly 600 output
-- Render table of contents separately
tocElements =
XMarkdown.API.viewTOC outputFor one-step compilation that parses and renders together, use compileSimple.
Compile source text to elm-ui HTML in one step (parse + render). The width of
the rendered text in pixels is docWidth. Use editCount = 0 for a static
document; in a live-editing context, increment it after each edit so the rendered
text updates correctly.
import Element exposing (Element)
import XMarkdown.API exposing (MarkupMsg, defaultCompilerParameters)Your Msg type should include | Render MarkupMsg.
Compile source text into a CompilerOutput structure.
This is the main compilation function that parses and processes XMarkdown source text. The output contains the rendered body, optional banner, table of contents, and title, which can then be displayed using the view functions.