CodeBlock
type CodeBlock =
{
Language: string option
Code: string
Meta: CodeBlockMeta
}| Assembly | Nacara.Core |
A fenced code block, as it was written.
Declared inside
Diff | A block written the way a diff is: + for a line added, - for one taken away |
Fields
Meta: CodeBlockMetaFunctions and values
claimsALanguage (language: string option) : bool
claimsALanguage (language: string option) : boolWhether a fence names a language a highlighter was meant to know.
| Parameter | |
|---|---|
language | What the fence wrote after its backticks. |
escapeAttribute (text: string) : string
escapeAttribute (text: string) : stringThe same, for text going inside an attribute rather than between tags.
A quote is harmless between tags and ends the value early inside one.
isColoured (highlighters: IHighlighter list) (block: CodeBlock) : bool
isColoured (highlighters: IHighlighter list) (block: CodeBlock) : boolWhether any highlighter claimed this block's language.
| Parameter | |
|---|---|
highlighters | What can colour the block. |
block | The block as the fence was written. |
language (block: CodeBlock) : string option
language (block: CodeBlock) : string optionWhat to colour a block as: lang= when it says, the fence otherwise.
| Parameter | |
|---|---|
block | The block as the fence was written. |
plain: Set<string>
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
prepare (highlighters: IHighlighter list) (block: CodeBlock) : PreparedCodeBlockHighlight a block and resolve its markers, leaving only the markup to decide.
| Parameter | |
|---|---|
highlighters | What 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. |
block | The 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 (renderers: ICodeBlockRenderer list) (highlighters: IHighlighter list) (block: CodeBlock) : stringRender with the first renderer that was registered, or the fallback.
| Parameter | |
|---|---|
renderers | What plugins contributed. The last one registered wins, so a theme registered after a plugin decides how a block looks. |
highlighters | What can colour the block. |
block | The block as the fence was written. |
renderMinimal (block: PreparedCodeBlock) : string
renderMinimal (block: PreparedCodeBlock) : stringThe 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 | |
|---|---|
block | A prepared block. |
Returns. <pre><code> with the token classes, and nothing else: no frame, no line numbers, no copy button.
source (block: PreparedCodeBlock) : string
source (block: PreparedCodeBlock) : stringWhat 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 | |
|---|---|
block | The block, prepared. |