jxxcarlson/scripta-compiler-v2/1.2.0

NOTE: the latest version is 1.3.0

ScriptaV2.API

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.

Overview

The API follows a two-step workflow:

  1. Compile source text into a CompilerOutput using compileOutput
  2. View the compiled output using viewBodyOnly or viewTOC

This 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.

Compilation

compileOutput : CompilerParameters -> List String -> CompilerOutput

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.

params =
    { defaultCompilerParameters
        | lang = MicroLaTeXLang
        , docWidth = 600
    }


output =
    compileOutput params
        [ "\\title{My Document}"
        , "\\section{Introduction}"
        , "Content here."
        ]

The language field in CompilerParameters determines which parser to use:

  • MicroLaTeXLang → MicroLaTeX parser
  • SMarkdownLang/MarkdownLang → XMarkdown parser
  • EnclosureLang → L0/Enclosure parser

Viewing

viewBodyOnly : Int -> CompilerOutput -> List (Element MarkupMsg)

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 output

This is useful when you want to display the main content separately from other document parts like the table of contents or title.

viewTOC : CompilerOutput -> List (Element MarkupMsg)

Render the table of contents from a CompilerOutput.

Generates a navigable table of contents based on the document structure (sections, subsections, etc.).

tocElements =
    viewTOC output

The table of contents automatically includes links to document sections and respects the document hierarchy.

Usage Example

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 output

Supported Languages

  • MicroLaTeXLang - LaTeX-like syntax with mathematical expressions via KaTeX
  • SMarkdownLang - Extended Markdown with scientific notation support
  • EnclosureLang - L0 language with bracket-based syntax
  • MarkdownLang - Standard Markdown (currently handled as SMarkdown)

See Also

For a simpler API that handles both compilation and rendering in one step, see ScriptaV2.APISimple.