Templates
Six rule sets ship inside the engine and are imported by bare name, as in use markdown (05 §1).
Each is an ordinary .self file in templates/: below is its source, a sample body, and that sample rendered by the engine at build time.
Press Try it on a source to edit the rules and the sample together, or open it in the playground.
Markdown use markdown
#The default rules of any file without a rules block (D40): the Markdown most people write, not full CommonMark. Tables, task lists and fenced code are rules like any other.
~~~ selfscribe
# Built-in Markdown template (the 90% people write; not full CommonMark)
set title Markdown
set slot $
line # $ -> h1 fold 1 key Ctrl+1
line ## $ -> h2 fold 2 key Ctrl+2
line ### $ -> h3 fold 3 key Ctrl+3
line #### $ -> h4 fold 4
line ##### $ -> h5 fold 5
line ###### $ -> h6 fold 6
line - [ ] $ -> li.task group ul nest input=checkbox
line - [x] $ -> li.task.done group ul nest input=checkbox checked
line - $ -> li group ul nest key Ctrl+Shift+8
line * $ -> li group ul nest
line + $ -> li group ul nest
line $#. $ -> li group ol nest group-start=$# key Ctrl+Shift+7
line > $ -> p group blockquote
line | $ | -> tr group table split "|" td
line |--$| -> hidden
line | --$| -> hidden
line |:--$| -> hidden
line | :--$| -> hidden
line --- -> hr
line *** -> hr
block ``` $ ... ``` -> code lang=$1 verbatim
block ~~~ $ ... ~~~ -> code lang=$1 verbatim
block <!-- ... --> -> hidden verbatim
inline <a id="$"></a> -> span id=$1
inline <a name="$"></a> -> span id=$1
inline  -> img alt=$1 src=$2
inline [$]($) -> a href=$2
inline **$** -> strong key Ctrl+B
inline __$__ -> strong bound
inline *$* -> em key Ctrl+I
inline _$_ -> em bound
inline ~~$~~ -> del
inline `$` -> code verbatim key Ctrl+E
inline [^$] -> footref
line [^$]: $ -> footnote key=$1
line ---page--- -> hr.self-pagebreak
# A longer fence holds examples that have fences of their own (CommonMark's rule).
block ```` $ ... ```` -> code lang=$1 verbatim
word https://$ -> a href="https://$1" keep url
word http://$ -> a href="http://$1" keep url
word www.$ -> a href="https://www.$1" keep url
~~~
# Release notes
This release makes **parsing** faster and *rendering* simpler. See [the spec](https://example.com).
## Changes
- Faster `parse`
- fewer allocations
- [x] Conformance suite passes
- [ ] Write the migration guide
| Target | Budget |
|--------|--------|
| native | 5 ms |
| wasm | 20 ms |
> Every rule is data.
```
self render notes.self > notes.html
```
Release notes
This release makes parsing faster and rendering simpler. See the spec.
Changes
- Faster
parse- fewer allocations
- Conformance suite passes
- Write the migration guide
| Target | Budget |
| native | 5 ms |
| wasm | 20 ms |
Every rule is data.
self render notes.self > notes.html
BBCode use bbcode
#Forum-style square-bracket markup. It shows attribute slots ([url=_]), a slot used both as attribute and content ([url]_[/url], D22) and quoted attribute interpolation (style="color: _1", D23).
~~~ selfscribe
set title BBCode
inline [b]_[/b] -> strong
inline [i]_[/i] -> em
inline [u]_[/u] -> u
inline [s]_[/s] -> s
inline [url=_]_[/url] -> a href=_1
inline [url]_[/url] -> a href=_1 _1
inline [img]_[/img] -> img src=_1
inline [color=_]_[/color] -> span style="color: _1" as colour
inline [size=_]_[/size] -> span style="font-size: _1" as size
block [quote] ... [/quote] -> blockquote
block [quote=_] ... [/quote] -> blockquote cite=_1
block [code] ... [/code] -> pre verbatim
block [spoiler] ... [/spoiler] -> details
block [list] ... [/list] -> ul
line [*] _ -> li
~~~
[b]Bold[/b], [i]italic[/i], [u]underlined[/u] and [s]struck[/s].
A [url=https://example.com]named link[/url] and a bare [url]https://example.com[/url].
[color=crimson]Coloured[/color] and [size=1.3em]larger[/size] text.
[quote]
Quoted text.
[/quote]
[list]
[*] first item
[*] second item
[/list]
[code]
preformatted, kept as is
[/code]
Bold, italic, underlined and struck.
A named link and a bare https://example.com.
Coloured and larger text.
Quoted text.
- first item
- second item
preformatted, kept as is
Colour comments use comments
#Colour-coded comment lists, the origin of Selfscribe. Each line rule carries its own CSS; word rules highlight TODO:, FIXME: and NOTE: anywhere in text.
~~~ selfscribe
# Colour-coded comment lists. The origin of Selfscribe.
set title Comments
# Each colour has a shade for light pages and one for dark pages, so every kind reads on both.
palette
critical #b42318 dark #ff8a80
question #175cd3 dark #8ab8ff
info #1d5f8a dark #8ecbf0
highlight #8a5a00 dark #f5c451
done #5f6b7a dark #a3adb9
comment #59636e dark #a4acb6
todo #a14a00 dark #ffab61
line // ! _ -> p.critical { color: var(--critical); font-weight: 600 } as critical
line // ? _ -> p.question { color: var(--question) } as question
line // ~ _ -> p.info { color: var(--info) } as info
line // * _ -> p.highlight { color: var(--highlight) } as highlight
line // - _ -> p.done { color: var(--done); text-decoration: line-through } as done
line // _ -> p.comment { color: var(--comment) } as comment
word TODO: -> span.todo { color: var(--todo); font-weight: 600 }
word FIXME: -> span.fixme { color: var(--critical); font-weight: 600 }
word NOTE: -> span.note { color: var(--info); font-weight: 600 }
~~~
// ! Ship the parser before Friday
// ? Do we need regex rules at all?
// ~ The kernel fits on one page
// * Longest pattern wins
// - Write the spec
// A plain comment. TODO: link the decisions. NOTE: they are numbered.
Ship the parser before Friday
Do we need regex rules at all?
The kernel fits on one page
Longest pattern wins
Write the spec
A plain comment. TODO: link the decisions. NOTE: they are numbered.
Form use form
#Markdown plus a form scope: ? lines become text inputs, [ ] checkboxes, ( ) radios, and {{name}} reads a variable. Controls are disabled unless the host enables forms (D45).
~~~ selfscribe
set title Form
use markdown
scope form
line ? _ -> label input=text
line [ ] _ -> label input=checkbox
line ( ) _ -> label input=radio
inline {{_}} -> var
~~~
# Sign-up
@scope form
? Your name
[ ] Subscribe to the newsletter
( ) Weekly
( ) Monthly
Hello {{who}}, welcome.
@end
Sign-up
Hello reader, welcome.
Plain use plain
#No rules at all: every line is text and consecutive lines merge into paragraphs. Use it as a clean base for your own rules.
~~~ selfscribe
# Plain text: no markup, and every line ends where it was written. It reads like
# prose in Source too: a reading column and no line numbers.
set title Plain
set linebreaks keep
set source-width reading
set line-numbers off
~~~
Nothing here is **markup**.
Lines merge into one paragraph.
A blank line starts the next one.
Nothing here is **markup**.
Lines merge into one paragraph.
A blank line starts the next one.
Workbook use workbook
#The root file of a workbook (05 §3). doc is a plugin target of the workbook host; outside one it renders as an unknown target with a warning, which is what you see here.
~~~ selfscribe
set title Workbook
line # _ -> section fold 1
line - _ -> doc nest
~~~
# Untitled workbook
- index.self
The template file has its own body.
- warning 4:1 unknown target 'doc'