Skip to content

CodeBlock

type CodeBlock =
    {
        Language: string option
        Code: string
        Meta: CodeBlockMeta
    }
AssemblyNacara.Core

A fenced code block, as it was written.

Declared inside

DiffA block written the way a diff is: + for a line added, - for one taken away

Fields

Language: string option
Code: string

Functions and values

claimsALanguage (language: string option) : bool

Whether a fence names a language a highlighter was meant to know.

Parameter
languageWhat the fence wrote after its backticks.
escapeAttribute (text: string) : string

The same, for text going inside an attribute rather than between tags.

A quote is harmless between tags and ends the value early inside one.

escapeHtml (text: string) : string

Escape text for placing in HTML. Renderers need this too.

isColoured (highlighters: IHighlighter list) (block: CodeBlock) : bool

Whether any highlighter claimed this block's language.

Parameter
highlightersWhat can colour the block.
blockThe block as the fence was written.
language (block: CodeBlock) : string option

What to colour a block as: lang= when it says, the fence otherwise.

Parameter
blockThe block as the fence was written.
plain: Set<string>

Fence languages that mean "this is not a language".

A block labelled text or console asks for no colour.

prepare (highlighters: IHighlighter list) (block: CodeBlock) : PreparedCodeBlock

Highlight a block and resolve its markers, leaving only the markup to decide.

Parameter
highlightersWhat can colour the block. The last one registered is asked first, and the ones before it cover what it declines; a language nobody claims is left as plain text.
blockThe block as the fence was written: its language, its annotations and its lines.

Returns. The block with its tokens coloured and its markers resolved to the lines and words they name - everything a renderer needs to decide markup and nothing more.

render (renderers: ICodeBlockRenderer list) (highlighters: IHighlighter list) (block: CodeBlock) : string

Render with the first renderer that was registered, or the fallback.

Parameter
renderersWhat plugins contributed. The last one registered wins, so a theme registered after a plugin decides how a block looks.
highlightersWhat can colour the block.
blockThe block as the fence was written.
renderMinimal (block: PreparedCodeBlock) : string

The fallback rendering, used when nothing better is registered.

Highlighting classes and nothing else. A theme registers an ICodeBlockRenderer to decide frames, line numbers and the rest.

Parameter
blockA prepared block.

Returns. <pre><code> with the token classes, and nothing else: no frame, no line numbers, no copy button.

source (block: PreparedCodeBlock) : string

What the block leaves you with: the code after the change it describes.

A folded line is kept, a deleted one is not, so a reader copies the code after the change.

Parameter
blockThe block, prepared.