How Selfscribe works
Every mark on this page is defined at its top. Change one and watch the page change.
What it shows
Write your own marks, and watch the page follow the rules you give them.
What you learn
Line, inline, word and block rules, a palette, values you set and show, a rule in long form, a scope.
Try this
- Change
brandin the palette to #c92a2a, and every purple thing on the page turns red.
How Selfscribe works
==the main point==the main point[[Ctrl]] + [[K]]Ctrl + K, keys to pressTODO ask the printerTODO ask the printer:rocket: :sparkles:🚀 ✨$e^{i\pi} + 1 = 0$e^{i\pi} + 1 = 0SelfscribeSelfscribe, in its own colourA rule is one line
A rule says where to look, what to look for, and what it becomes. Read this one left to right:
inline ==_== -> mark { background: … }
inline looks inside a line. ==_== is the pattern, and the _ stands for the words in between, which are kept. mark is what they become, and the braces hold its CSS, so the look travels with the file into every export. Two more from this page:
++inserted++inserted, an ins^^small caps^^small caps, for a quiet emphasisFour places to look
linematches a whole line, like the » line at the top.inlinematches a piece of a line, between two marks you type.blockmatches an opening line, the lines after it and a closing line, like::: demo.wordmatches a word anywhere, like each Selfscribe on this page. TODO gets a badge.
Colours, values, maths and diagrams
The purple on this page is one line of the palette: brand #6741d9 dark #b197fc, with a second shade for dark pages. Change it and every purple thing follows. Each colour also gets var(--on-NAME), text that reads on it in either shade: the TODO badge uses var(--on-todo).
A set line keeps a value and {{…}} shows it: this page is about Selfscribe 1.2, written for you.
A rule can become a plugin as well as an element. Maths is written as TeX, in a line like the one at the top or on its own:
flowchart LR
T[Your text] --> R{Its rules}
R --> P[The page]
R --> E[The editor's colours]
R --> X[Every export]
Rules for one part of a page
_ in a pattern: the words that are kept.math or chart.Outside the scope, a double colon is just text :: see?
When you want a mark as text
A backslash makes the next mark plain, so ==this== is not highlighted. Backslashes and the two scope lines are the only things fixed in the text. Everything else came from the rules block.
What if a rule has a typo?
The rest of the page still works. The broken line is underlined in the rules block, the status bar says what is wrong, and it often offers a fix.
How it's made
- Switch to Source to read the rules block beside the page. Its groups follow the order of this tour: line rules, inline rules, word rules, block rules, the long form and a scope.
- Each group starts with a comment line that says what you type and what you get. A rule nobody uses would be deleted, so every rule up there is drawn somewhere on this page.
- The rows at the top are
trylines, split at=>into two cells. The card around them is a::: demoblock, and itsheadline gives the two labels.
Try it yourself
- Change
brandin the palette to#c92a2a. Every purple thing on the page turns red, from the small labels above the headings to the word Selfscribe. - Change
set reader youtoset reader the whole team. The sentence under Three says it. - Add the line
**term** :: what it meansinside the glossary, between@scope glossaryand@end. A new row appears in the list. - Add a rule
word DONE -> span.done { color: var(--added); font-weight: 700 }under the TODO rule, then write DONE in a sentence. It turns green and bold.
Next: Your own notation turns a few words into drawings; Forum post adds tags to a borrowed markup.
~~~ selfscribe
# Lesson: Write your own marks, and watch the page follow the rules you give them.
# You learn: line, inline, word and block rules, a palette, values you set and show, a rule in long form, a scope.
# Try this: change `brand` in the palette to #c92a2a, and every purple thing on the page turns red.
# summary: Every mark on this page is defined at its top. Change one and watch the page change.
# category: syntax
# tags: document, simple
# uses: markup
#
# ---- "use markdown": headings, bold, lists and quotes, borrowed whole ------------
# Then this page adds its own rules. A later rule wins over an earlier one.
use markdown
set title How Selfscribe works
# ---- "set NAME value": a value you show anywhere with {{NAME}} ----------------------
set version 1.2
set reader you
# ---- A palette: each colour named once, with its shade for dark pages -------------
# Rules use a colour as var(--name). Change `brand` here and every purple thing follows.
palette
brand #6741d9 dark #b197fc
teal #0c7c7b dark #3cc7c6
note #1c64d8 dark #74a7ff
added #2da44e dark #57c878
marker #ffd43b dark #8a6d00
todo #c2410c dark #ff922b
soft color-mix(in srgb, var(--brand) 8%, transparent)
hair color-mix(in srgb, var(--brand) 16%, transparent)
# ---- Line rules: a mark at the start of a line styles the whole line ---------------
# "» text": the large opening paragraph.
line » _ -> div.lead { font-size: 1.22em; line-height: 1.55; opacity: 0.85; margin: 0 0 1.4em } as tour-lead
# "~ One": the small purple label above each heading.
line ~ _ -> div.kicker { font: 650 0.7em/1 var(--doc-font-ui); letter-spacing: 0.16em; text-transform: uppercase; color: var(--brand); margin: 2.6em 0 -1.1em } as tour-kicker
# "try A => B": split at => into two cells, what you type beside what you get.
line try _ -> div.try split "=>" span { display: grid; grid-template-columns: 1fr 1.15fr; gap: 0.2em 1.4em; align-items: center; padding: 0.7em 1.1em; border-top: 1px solid var(--hair) } as tour-try
# "head A => B": the two labels over the rows.
line head _ -> div.head split "=>" span { display: grid; grid-template-columns: 1fr 1.15fr; gap: 1.4em; padding: 0.75em 1.1em 0.6em; font: 700 0.68em/1 var(--doc-font-ui); letter-spacing: 0.16em; text-transform: uppercase; color: var(--brand) } as tour-head
# ";; a, b, c": split at each comma into a row of chips.
line ;; _ -> div.chips split "," span.tour-chip { display: flex; flex-wrap: wrap; gap: 0.4em; margin: 0.6em 0 1.2em } as tour-chips
# A class styles every element with that class, here the chips the split rule makes.
class tour-chip { display: inline-block; padding: 0.15em 0.7em; border-radius: 999px; font: 600 0.78em/1.6 var(--doc-font-ui); background: color-mix(in srgb, var(--teal) 14%, transparent); color: var(--teal) }
# ---- Inline rules: words between two marks you type, inside a line -------------
inline ==_== -> mark.hl { background: color-mix(in srgb, var(--marker) 45%, transparent); color: inherit; padding: 0 0.2em; border-radius: 3px } as tour-hl
inline ++_++ -> ins { text-decoration: none; background: color-mix(in srgb, var(--added) 18%, transparent); padding: 0 0.2em; border-radius: 3px } as tour-ins
inline [[_]] -> kbd { font: 600 0.8em var(--doc-font-mono); padding: 0.1em 0.45em; border-radius: 5px; border: 1px solid color-mix(in srgb, currentColor 25%, transparent); border-bottom-width: 2px } as tour-kbd
inline ^^_^^ -> span.caps { font-variant: small-caps; letter-spacing: 0.06em; font-weight: 600 } as tour-caps
# {{name}} shows a value from a `set` line above.
inline {{_}} -> var { font-weight: 650; color: var(--brand) } as tour-var
# A plugin as the target: :rocket: becomes the emoji. `bound` keeps it out of the middle of words.
inline :_: -> emoji bound
# ---- Word rules: one word or phrase, wherever it appears ---------------------
word Selfscribe -> span.brand { font-weight: 700; letter-spacing: -0.01em; color: var(--brand) } as tour-brand
# var(--on-todo) is a text colour that reads on the todo colour, light or dark.
word TODO -> span.todo { font: 700 0.72em/1 var(--doc-font-ui); letter-spacing: 0.08em; padding: 0.25em 0.5em; border-radius: 4px; background: var(--todo); color: var(--on-todo); vertical-align: 0.15em } as tour-todo
# ---- Block rules: an opening line, the lines inside, a closing line ---------------------
# "::: demo" … ":::": a card around rows of what you type and what you get.
block ::: demo ... ::: -> div.demo { margin: 0.4em 0 1.4em; border-radius: 16px; overflow: hidden; border: 1px solid var(--hair); background: linear-gradient(180deg, var(--soft), transparent 70%) } as tour-demo
class demo > div:first-child { border-top: 0 }
block ::: note ... ::: -> aside.note { padding: 0.8em 1.1em; margin: 1.2em 0; border-radius: 12px; border-left: 4px solid var(--note); background: color-mix(in srgb, var(--note) 9%, transparent) } as tour-note
# A faq block folds: its "Q." line is the part you click.
block ::: faq ... ::: -> details { padding: 0.7em 1em; border-radius: 12px; border: 1px solid color-mix(in srgb, currentColor 16%, transparent) } as tour-faq
line Q. _ -> summary { font-weight: 650; cursor: pointer } as tour-q
# `verbatim` hands the text inside to a plugin untouched: TeX maths and a Mermaid diagram.
block $$ ... $$ -> math verbatim
inline $_$ -> math verbatim
block ``` mermaid ... ``` -> mermaid verbatim
# ---- The long form: one rule as named lines, with a note for hover cards
rule tour-aside
where line
match // _
out div.aside
style font-style: italic; opacity: 0.7; padding-left: 1em; border-left: 2px dotted currentColor; margin: 0.6em 0
doc A margin remark: a line starting with two slashes.
editor colour #868e96
# ---- A scope: these rules apply only between @scope glossary and @end ----------
scope glossary
line _ :: _ -> div.term { padding: 0.45em 0 0.45em 8em; text-indent: -8em; border-bottom: 1px solid color-mix(in srgb, currentColor 12%, transparent) } as tour-term
inline **_** -> strong { display: inline-block; min-width: 8em; text-indent: 0; color: var(--brand) } as tour-term-key
scope
~~~
# How Selfscribe works
» This page is a plain text file. The block at its top says what every mark on it means, and nothing here is built in. Change a rule, and the page changes with it.
::: demo
head You type => You get
try `==the main point==` => ==the main point==
try `[[Ctrl]] + [[K]]` => [[Ctrl]] + [[K]], keys to press
try `TODO ask the printer` => TODO ask the printer
try `:rocket: :sparkles:` => :rocket: :sparkles:
try `$e^{i\pi} + 1 = 0$` => $e^{i\pi} + 1 = 0$
try `Selfscribe` => Selfscribe, in its own colour
:::
;; plain text, rules in the file, looks in the rules, no code
~ One
## A rule is one line
A rule says **where** to look, **what** to look for, and **what it becomes**. Read this one left to right:
`inline ==_== -> mark { background: … }`
`inline` looks inside a line. `==_==` is the pattern, and the `_` stands for the words in between, which are kept. `mark` is what they become, and the braces hold its CSS, so the look travels with the file into every export. Two more from this page:
::: demo
try `++inserted++` => ++inserted++, an `ins`
try `^^small caps^^` => ^^small caps^^, for a quiet emphasis
:::
~ Two
## Four places to look
- `line` matches a whole line, like the » line at the top.
- `inline` matches a piece of a line, between two marks you type.
- `block` matches an opening line, the lines after it and a closing line, like `::: demo`.
- `word` matches a word anywhere, like each Selfscribe on this page. TODO gets a badge.
::: note
**The longer pattern wins.** When two rules could match in the same place, the one with more written characters wins, so `**bold**` beats `*italic*`. If they are equal, the later rule wins. That is how a document changes a rule it borrowed.
:::
// A remark in the margin. Its rule is written in the long form, with a note you see when you hover it in the rules block.
~ Three
## Colours, values, maths and diagrams
The purple on this page is one line of the palette: `brand #6741d9 dark #b197fc`, with a second shade for dark pages. Change it and every purple thing follows. Each colour also gets `var(--on-NAME)`, text that reads on it in either shade: the TODO badge uses `var(--on-todo)`.
A `set` line keeps a value and `{{…}}` shows it: this page is about Selfscribe {{version}}, written for {{reader}}.
A rule can become a plugin as well as an element. Maths is written as TeX, in a line like the one at the top or on its own:
$$
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}
$$
```mermaid
flowchart LR
T[Your text] --> R{Its rules}
R --> P[The page]
R --> E[The editor's colours]
R --> X[Every export]
```
~ Four
## Rules for one part of a page
@scope glossary
**rule** :: One line of the rules block: where, what, and what it becomes.
**slot** :: The `_` in a pattern: the words that are kept.
**plugin** :: Something a rule can become besides an element, such as `math` or `chart`.
**scope** :: Rules that apply only between an at-scope line and an at-end line.
@end
Outside the scope, a double colon is just text :: see?
~ Five
## When you want a mark as text
A backslash makes the next mark plain, so \==this\== is not highlighted. Backslashes and the two scope lines are the only things fixed in the text. Everything else came from the rules block.
::: faq
Q. What if a rule has a typo?
The rest of the page still works. The broken line is underlined in the rules block, the status bar says what is wrong, and it often offers a fix.
:::
## How it's made
- Switch to Source to read the rules block beside the page. Its groups follow the order of this tour: line rules, inline rules, word rules, block rules, the long form and a scope.
- Each group starts with a comment line that says what you type and what you get. A rule nobody uses would be deleted, so every rule up there is drawn somewhere on this page.
- The rows at the top are `try` lines, split at `=>` into two cells. The card around them is a `::: demo` block, and its `head` line gives the two labels.
## Try it yourself
1. Change `brand` in the palette to `#c92a2a`. Every purple thing on the page turns red, from the small labels above the headings to the word Selfscribe.
2. Change `set reader you` to `set reader the whole team`. The sentence under Three says it.
3. Add the line `**term** :: what it means` inside the glossary, between `@scope glossary` and `@end`. A new row appears in the list.
4. Add a rule `word DONE -> span.done { color: var(--added); font-weight: 700 }` under the TODO rule, then write DONE in a sentence. It turns green and bold.
Next: *Your own notation* turns a few words into drawings; *Forum post* adds tags to a borrowed markup.