SelfscribeDownloadOpen the app

Rules

When what you write has a shape of its own, such as a chat, a script or a contract, a few rules of your own make it read naturally as text and look right on the page.

Read a rule

#
selfscribe
line   Ana: _   -> p.ana   { color: steelblue }

Read it left to right. line says where to look, Ana: _ is the pattern, p.ana is what it becomes, and the braces hold CSS for how it looks. In the pattern, _ stands for the text that varies, and that text is kept. Separate the parts with spaces, and start a comment with #.

Choose where a rule looks

#
The text
~~~ selfscribe
use markdown
word    SHALL            -> strong  { color: crimson }
line    // _             -> p       { opacity: 0.55 }
inline  ==_==            -> mark
block   ::: tip ... :::  -> aside   { border-left: 3px solid teal; padding-left: 1em }
~~~
The tenant SHALL keep the ==garden== tidy.

// Check the lease dates.

::: tip
Mow before the inspection.
:::
The page
WhereMatches
wordA word or phrase anywhere outside code.
lineA whole line. A trailing _ takes the rest of it.
inlineA piece of a line between two marks you type, such as ==_== or [[_]].
blockAn opening line, the lines after it, and a closing line. ... stands for the lines.

There are no regular expressions. When two rules could match, the longer pattern wins.

Mark a word that follows a sign

#

In a word rule, _ takes one word, so a sign needs no closing mark:

The text
~~~ selfscribe
use markdown
word  @_  -> span  keep  { color: teal; font-weight: 600 }
word  #_  -> span  keep  { background: #e6fcf5; padding: 0 .3em; border-radius: 4px }
~~~
@ana, the boat leaves from #pier-4 at nine.
The page

The comma after @ana stays outside, and keep shows the sign as well as the word.

Change how a rule behaves

#

Words after what the rule becomes change how it works:

OptionWhat it does
group ulWraps neighbouring matches in one element: line - _ -> li group ul makes one list.
nestPuts more-indented lines inside, for outlines and replies.
foldLets the section fold away, like a heading.
split "," tdCuts the line into pieces at each comma, each piece a td.
keepKeeps the marks in the output.
boundMatches only at the edges of words.
verbatimApplies no other rules inside, as in code.
key Ctrl+Shift+HApplies the rule from the keyboard: it wraps the selection, or turns the line into it.
as NAMENames the rule, for off NAME and the Inspector.

Give the page a look

#

Click Look in the status bar, or write one line:

The text
~~~ selfscribe
use markdown
set style paper numbered
~~~
# The harbour

## The market
Fish from six, bread from seven.

## The ferry
Every hour, on the hour.
The page

Look words add up. paper, newspaper and academic are whole looks. dark and light set the page colour, wide and compact the spacing, and serif, sans, mono and justified the type. numbered, dropcap and columns change the structure.

File › Page setup… writes the other lines for you: set font Literata, set heading-font Inter, set width 40em for the reading column, and set lang en-GB for spelling and hyphenation. set theme sepia colours the whole app while the document is open.

Name your colours once

#

Write each colour once in a palette and use it as var(--name). The colour after dark is for dark pages. An entry can mix an earlier one with color-mix(), and the mix follows the dark shade by itself:

The text
~~~ selfscribe
use markdown
palette
  harbour  #0b6e8a  dark #6cc8e0
  tint     color-mix(in srgb, var(--harbour) 14%, transparent)
word  NOTE:  -> strong  { color: var(--harbour) }
line  !! _   -> p  { background: var(--tint); border-left: 3px solid var(--harbour); padding: .3em .8em }
~~~
NOTE: the ferry leaves at six.

!! The last boat is at nine.
The page

Each colour also gets --on-NAME, near-black or white, whichever reads better on it: { background: var(--harbour); color: var(--on-harbour) }.

Style several rules alike

#

Rules that should look alike share a class, styled once. Each rule adds only what differs:

The text
~~~ selfscribe
use markdown
class badge  { font: 700 .72em/1.6 sans-serif; padding: 0 .5em; border-radius: 5px; color: white }
word  TODO  -> span.badge  { background: #c2410c }
word  DONE  -> span.badge  { background: #0b6e8a }
~~~
TODO book the ferry. DONE pay the harbour fee.
The page

A rule's own CSS wins over its class. A class also styles what group wraps and the pieces of split. After the name, a class may take a pseudo-element and one element inside: class crumb::after { content: " › " }, class card h3 { margin: 0 }.

Add CSS of your own

#

View › Custom CSS… adds a style block at the end of the document, and the rule that makes it work:

selfscribe
block  ``` style ... ```  -> style  verbatim

View › Style every document of the folder edits selfscribe.css at the top of the folder. The page's own colours are tokens such as --doc-bg and --doc-link, listed in Reference.

Borrow rules

#
selfscribe
use markdown              # a built-in rulebook
use ./house-style.self    # rules kept in a file beside this one
off inline **_**          # switch off one borrowed rule

Your own rules win over borrowed ones. To keep rules for other documents, choose More › Save to a rulebook… in the Inspector, then use it by name. A palette line after a use line recolours what it borrowed.

Make your own notation

#

A plugin's language can be long. A rewrite lets you write a short form and spells out the long one:

text
rewrite block ``` route ... ``` -> flow
  line   _1: _2    ->  node _1 "_2" :service
  line   _1 > _2   ->  _1 -> _2 moving
  first            ->  set direction=LR

With this rule, a route block of pier: Ferry pier and pier > island is drawn as a flow diagram. Each indented line is a shortcut: its left side is what you write, its right side what it stands for, and _1, _2 carry the text across. first and last add a line at the top or the end. Lines that fit no shortcut pass through as written.

Let the editor write the rule

#

Select an example of your mark, such as !! careful !!, and choose Make a rule from the selection… in the Inspector. The wizard marks the part that varies, and Add another example helps it tell the mark from the text. When you repeat a mark no rule covers, the Inspector offers to make the rule.

To change a mark you already use, put the caret on it and choose More › Change this rule's mark…. Every use in the document is rewritten as one step.

Rules to copy

#

Chat bubbles. group div.chat wraps each run of messages in one element, and class chat styles it.

The text
~~~ selfscribe
use markdown
class chat  { display: flex; flex-direction: column; gap: .35em }
class msg   { border-radius: 14px; padding: .35em .8em; max-width: 75% }
line  Ana: _  -> div.msg  group div.chat  { background: #e7f0ff; align-self: flex-start }
line  Me: _   -> div.msg  group div.chat  { background: #1864ab; color: white; align-self: flex-end }
~~~
Ana: Are you on the 9:40?
Me: Running. Hold the gangway!
Ana: Too late, see you on the next one.
The page

Chips, keys and notes to yourself. split cuts one line into chips, and hidden keeps a line in the file and off the page.

The text
~~~ selfscribe
use markdown
line    facts _  -> div  split "|" span.fact  { display: flex; gap: .5em }
class   fact     { padding: .2em .8em; border-radius: 99px; background: #fff4e6 }
inline  [[_]]    -> kbd
line    // _     -> hidden
~~~
facts 40 min | Serves 6 | Easy

Press [[Ctrl]] + [[P]] to print the recipe.

// Check the oven temperature.
The page

The examples, under File › New from… › An example…, show many more at full size.

Find out why a rule does nothing

#
  • A problem shows on the rule's line and in the status bar, often with a fix.
  • With the caret on a rule, the Inspector says what it matches and how often. On any text,

    it says which rule made it and which rules it won over.

  • An inline pattern needs a mark at both ends: ==_== works, _! does not.
  • The longer pattern wins: **_** beats *_*, whichever comes first.