jxxcarlson/scripta-compiler-v3/1.0.1

Scripta

Public API for the Scripta compiler.

Options

type alias Options =
Options

Opaque compiler options. Build with defaultOptions and the with* functions.

defaultOptions : Options

Default options: no filter, 800px window and content width, light theme, no table of contents, default sizing, unlimited heading level.

withTheme : Theme -> Options -> Options

Set the theme.

withWindowWidth : Int -> Options -> Options

Set the window width in pixels.

withContentWidth : Int -> Options -> Options

Set the content (text column) width in pixels.

withTOC : Bool -> Options -> Options

Show or hide the table of contents.

withMaxLevel : Int -> Options -> Options

Set the maximum heading level to render.

withSizing : SizingConfig -> Options -> Options

Set the sizing configuration.

withFilter : Filter -> Options -> Options

Set the forest filter.

type Theme
= Light
| Dark

Light or dark theme.

type Filter
= NoFilter
| SuppressDocumentBlocks

Forest filter. NoFilter renders everything; SuppressDocumentBlocks hides document and title blocks.

type alias SizingConfig =
SizingConfig

Sizing/spacing configuration (a record).

defaultSizing : SizingConfig

Default sizing configuration.

Documents and rendering

type alias Document =
Document

An opaque parsed document. Produced by parse / reparse, consumed by render and the Scripta.Document query functions.

type alias Edit =
Edit

A single source edit: a character range removed replaced by inserted, starting at character offset in the pre-edit document.

type Event
= ClickedId String
| ClickedFootnote
{ targetId : String
, returnId : String
}
| ClickedCitation
{ targetId : String
, returnId : String
}
| ClickedImage String
| ClickedLink String
| HighlightedId String

An interaction event emitted by rendered output.

  • ClickedId — the user clicked an element with the given id.
  • ClickedFootnote / ClickedCitation — jump to a target, remembering a return id.
  • ClickedImage — the user clicked an image (url).
  • ClickedLink — the user clicked an internal document link (slug).
  • HighlightedId — request to highlight the element with the given id.
type alias Output msg =
{ title : Html msg
, body : List (Html msg)
, toc : List (Html msg)
, banner : Maybe (Html msg)
}

Rendered output, polymorphic in the message type so mapEvent can retarget it.

parse : Options -> String -> Document

Parse source text into a Document (cold path: full parse).

For editor keystroke updates use reparse, which is incremental.

reparse : Options -> Document -> String -> Document

Re-parse source text incrementally, reusing the previous Document's cache and accumulator where it is safe to do so. Use this for editor keystroke updates; use parse for initial load and document switches.

render : Options -> Document -> Output Event

Render a parsed Document to HTML output carrying Events.

compile : Options -> String -> Output Event

Parse and render in one step (cold path).

mapEvent : (Event -> msg) -> Output Event -> Output msg

Retarget a whole Output from Event to the consumer's own message type.

applyEdit : Edit -> Document -> Document

Apply one edit's fast metadata shift to a Document, keeping the RL-sync map (data-begin/data-end/data-lines/id) valid without reparsing content.

This is the high-frequency path (run per keystroke). It does NOT refresh block content or rendering — use reparse on a longer debounce for that.

applyEdits : List Edit -> Document -> Document

Apply a queue of edits in order (each in the coordinate space of the document produced by the previous edit).

Static export

exportHtml : Options -> Document -> String

Export a parsed Document as a complete standalone HTML document (a single String).

The output is meant for static viewing or printing: it includes a <head> that pulls KaTeX from a CDN for math rendering and a default stylesheet, plus a <body> containing the title, optional TOC, and rendered content. None of the interactive editor-sync handlers are included.

{ title : String
, authors : List String
}
-> Document
-> String

Export a parsed document as a complete LaTeX document, with preamble, ready for xelatex. The title and authors go into the document's title block.

exportRawLaTeX : Document -> String

Export a parsed document as LaTeX: the body only, without the preamble.

Source

prettyPrint : String -> String

Pretty-print Scripta source text: parse it and write it back out with standard indentation and spacing.