jxxcarlson/xmarkdown-compiler/1.0.1

NOTE: the latest version is 2.2.6

XMarkdown.API

XMarkdown.API provides the core compilation interface for converting XMarkdown (SMarkdown) source text into renderable elm-ui Elements.

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

params =
    { defaultCompilerParameters
        | docWidth = 600
    }


output =
    compileOutput params
        [ "# My Document"
        , "## Introduction"
        , "Content here."
        ]

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.

type alias BlockMatch =
BlockMatch

Re-export BlockMatch type for searching

compile : CompilerParameters -> List String -> CompilerOutput
fromMsg : Int -> MarkupMsg -> Maybe SyncHighlight
searchBlocksContainingText : CompilerParameters -> List String -> String -> List BlockMatch

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"
viewEditor : Config msg -> Html msg
compileString : CompilerParameters -> String -> List (Element MarkupMsg)
compileStringWithTitle : String -> CompilerParameters -> String -> List (Element MarkupMsg)
defaultCompilerParameters : CompilerParameters
editorView : Config msg -> Html msg

Usage Example

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 output

See Also

For one-step compilation that parses and renders together, use compileSimple.

compileSimple : CompilerParameters -> String -> List (Element MarkupMsg)

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.