Litemark.parse
Litemark.parse($text, $options={}) -> HtmlString
Description
Parse a string with Litemark content and return an HTML TypeString.
Options
| Option | Value | Description |
|---|---|---|
features |
string | Pipe-separated list of features or “:featureSet” |
customTags |
map | Map of custom square tags. |
urlHandler |
function | A callback function to process URLs. |
Litemark.parse($text, {
features: 'text|lists|headings'
})
// Using a :featureSet to activate a group of features
Litemark.parse($text, {
features: ':forum'
})
Activating Features
This is a list of all feature flags, and corresponding :featureSets.
:comment :forum :blog/:wiki :xDangerAll
text x x x x
lists x x x
headings x x x
blocks x x x
images x x x
links x x x
tables x x
inline x x
callouts x x
icons x x
toc x x
indexLinks x
xDangerHtml x
Feature Flags
text: basic text formatting, i.e. bold, italiclists: bulleted and numbered listsheadings: text headings, i.e.## Heading 2blocks: blockquotes and pre-formatted code blocksimages: inline image tags[image]links: link tags that allow custom link text[link]tables: table tagsinline: inline tags like[del]and[sup]callouts: callouts like[info]and[warning]icons: THT's built-in SVG icons[icon]toc: table of contents tag[toc]
Critical Feature Flags
indexLinks: Allow search crawlers to index links. By default, this is disabled, meaning all links haverel="nofollow"to deter link spamming.xDangerHtml: Allow inline HTML tags. Should never be used for outside users.
URL Handler
By default, Litemark will auto-hyperlink the most common URL patterns.
To override this behavior, provide a callback that takes a URL object and returns an HTML string.
Litemark.parse($text, {
urlHandler: fun ($url) {
$tag = html'<a href="{}">external link</a>'
return $tag.fill($url)
}
})
Custom Square Tags
You can create your own square tags via the customTags field.
Command names must:
- Include the arity (the number of parameters it requires)
- Be all lowercase
The value can be:
- An HTML TypeString with numbered placeholders.
- A callback function that returns an HTML TypeString.
$text = '''
Here is a [squiggle].
The truth is, [spoiler | the butler did it]
Created by [user | Thrifty33]
'''
Litemark.parse($text, {
customTags: {
squiggle0: html'~^~^~^~^~'
spoiler1: html'<span class="spoiler">{1}</span>'
// Link to user (e.g. /user/thrifty33)
user1: fun ($name) {
$nameSlug = $name.slug()
$link = html'<a href="/user/{}">{}</>'
return $link.fill($nameSlug, $name)
}
}
})
Custom Tags in Templates
To register custom tags for use in Litemark templates, add a litemarkCustomTags field to app.jcon and assign a Map of strings.
// config/app.jcon
//--------------------------------
app {
// (other fields)
litemarkCustomTags: {
tag1: <b>CUSTOM: {1}</b>
other0: <b>OTHER</b>
}
}