ScriptaV2.API provides the core compilation interface for converting markup text into renderable elm-ui Elements. This module supports three markup languages: MicroLaTeX, SMarkdown/XMarkdown, and Enclosure/L0.
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.
import ScriptaV2.API
import ScriptaV2.Types exposing (defaultCompilerParameters)
import ScriptaV2.Language exposing (Language(..))
-- Configure compiler
params =
{ defaultCompilerParameters
| lang = MicroLaTeXLang
, docWidth = 600
, editCount = 0
}
-- Compile source text
output =
ScriptaV2.API.compileOutput params
[ "\\section{Introduction}"
, "This is a document with \\strong{bold} text."
, ""
, "\\subsection{Details}"
, "More content here."
]
-- Render the document body
bodyElements =
ScriptaV2.API.viewBodyOnly 600 output
-- Render table of contents separately
tocElements =
ScriptaV2.API.viewTOC outputFor a simpler API that handles both compilation and rendering in one step,
see ScriptaV2.APISimple.
Compile source text into a CompilerOutput structure.
This is the main compilation function that parses and processes markup text according to the language specified in
CompilerParameters. The output contains the rendered body, optional banner, table of contents, and title, which can then be displayed using the view functions.The language field in CompilerParameters determines which parser to use: