Chapter 74

The profile editor and profile building blocks

A syntax profile tells Pilcrow what your markup means. This chapter describes the profile editor control by control, and then lists every building block a profile can use. For a task-based introduction, see Chapter 37 to Chapter 39.

Open the editor from Settings ▸ Library ▸ Syntax Profiles: New starts a profile, Edit changes a custom one, and Duplicate copies a built-in profile so you can change the copy. The editor's title is Edit Profile, with Cancel, Save and Profile Help (which opens the in-app reference to these building blocks). On a narrow screen, a Profile section switch chooses between Overview, Rules and Test Sample; on a wide one all three show at once.

Overview#

FieldWhat it does
NameThe profile's name, shown in the status bar menu and Settings.
DescriptionA note about the profile.
File extensions (comma-separated)The extensions that choose this profile for a file. Two profiles cannot share an extension.
InheritsNone, or another profile whose rules this one builds on.
SyntaxExtends Markdown or Replaces Markdown (below).
At a glanceCounts of Block rules, Inline rules and Nesting rules.
Edit Advanced JSON…Opens the profile as JSON for fields the guided editor does not expose. Apply keeps your JSON changes; Cancel discards them.

Extends Markdown adds your rules to Markdown's: its headings, lists, emphasis and the rest are still read, and your block and inline rules add to them. A rule that is an unchanged copy of one of the CommonMark profile's describes what Markdown already does, and is left to it. Replaces Markdown makes your rules the whole syntax, so Markdown constructs stop being recognized. With it, one rule must produce End of line, or nothing separates into paragraphs. The editor warns "Add a rule whose output node is "newline", or nothing will separate into paragraphs", and the profile cannot be saved until one exists. It also lists any output types the profile does not define.

Rules#

Rules come in three groups.

Block rules#

A block rule recognizes whole lines and blocks. Add rule adds one. Each rule has a Pattern, a Match type, what it Produces, and Options. A rule is removed with its Delete button. With none, the editor says "No rules yet. Add one to recognize a block construct."

Inline rules#

An inline rule recognizes text inside a line. Add inline rule adds one. Inline rules offer four match types (Literal prefix, Literal exact, Regex (bounded) and Delimiter pair); block rules offer all seven.

Nesting rules#

Nesting rules say which outputs may sit inside which. Each has a Parent node and Allowed children (comma separated). Empty means unrestricted: "No restrictions. Every node type may nest inside any other." Add nesting rule adds one.

Match types#

Match typeReads the pattern asBlockInline
Literal prefixText the construct starts with.yesyes
Literal exactThe whole text of the construct.yesyes
Line-start prefixText at the start of a line, such as # .yes
Indented blockLines that begin with the pattern, such as four spaces or a tab. Consecutive ones, and blank lines between them, are one block, shown without the indent.yes
Fenced blockA line that opens a block, closed by a matching line.yes
Regex (bounded)A regular expression. Pilcrow warns before saving one that could get stuck: "This regex could hang the editor — simplify it."yesyes
Delimiter pairThe same mark on both sides of text on one line, such as %% in %%this%%. There is no space just inside the marks.yesyes

In a regular expression, (?<name>…) names a part of the match. See Named parts below.

Rule options#

Each rule's Options group offers:

OptionWhat it does
PriorityRules with a higher priority are tried first.
Only at the start of a lineKeeps a rule from matching mid-line.
Named parts become attributesEach named part of a regular expression becomes an attribute of the output. The editor lists "Parts in this pattern" and "Parts this output reads". For an output that holds text, such as bold or a link, the text shown is the part named text if there is one, else the last part that matched.
ProducesWhat the rule makes: an output from the lists below, or a Custom name.
Custom node nameThe name for a Custom output.
Fixed attributesParts that have the same value every time, added with Add attribute (a Name and a Value). A value may include a named part, written {name}: an e-mail rule whose pattern names the address can give its link the url mailto:{address}.
Insert textWhat the Insert menu writes for this rule, exactly as it should appear, with $0 where the caret should go. A rule matched by a regular expression, a block or indentation needs this, or the Insert menu leaves it out.
Only after a blank lineFor an indented block: an indented line right after text stays part of that text, such as a list item's next line.
After Return at the end of a lineFor lists and quotes: Automatic (repeats bullets and quotes, counts up numbered items, and starts task items unchecked), Repeat the marker, Count up, Start fresh from the marker, or Add nothing.

Fenced and delimited blocks#

For a Fenced block rule, Block holds says what is inside:

ChoiceMeaning
Nothing yetNot set.
Text, shown as writtenCode or preformatted text.
Nothing — hiddenA comment, left out of the document.
Other blocks, in a boxA quote, sidebar or admonition holding paragraphs, lists and more.
Other blocks, no boxThe blocks join the surrounding text; the lines only group them.
A tableSee Tables, below.
A table drawn in textA grid or aligned columns of text that runs from its opening line to the next blank line, such as reStructuredText's.
Indented text under a line ending in a markerThe opening line is prose that ends in the marker, as reStructuredText's :: does; the prose stays a paragraph, and the text set in under it after a blank line is shown as written.
Indented text under an opening lineA directive such as .. code-block::, which holds the indented lines under it and has no closing line.

Closing line is the line that ends the block; empty means the same line as the opening one ("Same as the opening line"). A delimiter that is not a regular expression, such as +++, is matched as plain text. Closing line repeats the opening mark, at least as often is for Markdown-style fences: the closing line is the opening line's first character repeated at least as many times, so a longer fence holds a shorter one as text. A text block's language, when the opening line names a known one, is coloured in the editor.

Tables#

A table block's options:

OptionWhat it does
LayoutGrid with rule lines (cells between | with a rule line between rows) or Aligned columns (columns lined up under a first rule line).
Cell separatorThe text that starts each cell.
Rule line pattern, Header rule line patternLines that draw only a rule, and the one that ends the header.
Row ends withA mark that ends each row, as a LaTeX tabular does.
Spanning cell patternA cell that spans columns.
Cell options patternA regular expression for what may come just before a cell's separator; a part named colspan makes the cell span that many columns.
Column list separator, Repeat markerHow a columns list is written: with , and *, 3* counts three columns.
First line before a blank line is the headerThe header row is implied by layout.
FormatsOther ways to write the cells, each a name and a separator (such as csv and ,), added with Add format and chosen with the table's format part.

Profile-wide settings#

SettingWhat it does
Nest lists by markerEach new marker, such as ** after *, starts a deeper level, whatever the indentation.
List continuation lineA line, alone after a list item, that attaches the next block to the item.
Keep single line breaksA line break inside a paragraph stays a line break.
Give headings idsA heading with no id of its own gets one from its title: lower case, words joined by the word separator, after the prefix (Heading id prefix, Heading id word separator). With _ and _, "Getting Started" is _getting_started, so a cross-reference to it shows the title. A repeated title adds the separator and a number.
Number headingsOnce the document defines the attribute named in When the document defines, such as AsciiDoc's :sectnums:, headings from From heading level down are numbered: 1., 1.1., 2.. Headings before the definition are not.
Numbered captionsA titled block of an output listed here, such as image, table or example, gets the Label and its own number before its title (for example "Figure 1."), at the Caption place, Above or Below the block. Added with Add caption.

Inline marks that pair by what stands around them#

A language such as Markdown writes bold and italic with a run of characters that opens or closes depending on the characters beside it, and a code span or link with brackets, so one pattern for the whole construct cannot find them. Turn on Read marks by what stands around them to describe them.

SettingWhat it does
Escape characterA character that makes the next one plain.
Code span characterA run of this character opens a span that the next run of the same length closes.
Run marksMarks that pair as runs, added with Add run mark. Each has a Mark, what One mark draws and what Two marks draw, and May open or close inside a word (off for _).
Pair marksMarks that pair with a run of the same length, added with Add pair mark: the Mark, what it Draws, and Only when this setting is on, a syntax setting such as highlight that must be on (or Always).
Links and web addressesImage prefix, Address written on its own is enclosed by, Schemes that begin a bare address, Line that defines a label has, and Footnote label begins with (the character after a label's opening bracket that makes it a footnote: [^note] is drawn as a footnote reference when a line begins [^note]:).

Marks pair within a line. Code, escaped characters and a link's address are plain text to the marks around them.

Styled source#

With Styled Source on, the editor draws a document in the look of its syntax: larger headings, bold and italic runs, quote bars, list indents, task boxes, rules, links and code cards, and hides the marks that make them (with Hide Markers on) except on the line the caret is on. The editor knows nothing about any one syntax: a rule says what its match is by carrying a styling entry, and a rule without one is coloured but not restyled.

Every rule's Options has a Styled source group:

FieldWhat it does
RoleWhat the match is, or Not styled. For one construct inside a line: heading, strong, emphasis, code, strike, highlight, underline, link, subscript, superscript. For a whole line: rule (a thematic break), list (a list item's marker, including its indent and the space after it), task (a marker followed by a checkbox) and quote (the > marks of a quoted line). For a block recognized whole: codeBlock. For a block whose opening and closing lines are separate matches: quoteRegion. For a table, equation or diagram drawn as a picture: renderedBlock.
Content groupThe capture group, counting from 1, that holds what the construct is about: the word inside *bold*, the title in \section{Title}. What the match has besides it is the construct's own marks, which Hide Markers hides. 0 means the whole match is content and nothing hides, as for a web address. Leave it out when the match is only marks, such as a heading's == .
Heading level, Level groupA heading's level, 1 to 6. Left out, it is the number at the end of the rule's output name (heading2), or the length of the capture group that holds a run of #.
Marker groupFor a list or task, the capture group that is the marker with its indent and the spaces after it, when the match begins with something else, such as the > of a quoted item.
Styles to the end of the lineStyles from the match to the end of the line, for a rule that matches only a heading's marker and leaves its title as the text that follows.
Draws asFor a rendered block, what it is: a table, math or diagram, or Not a picture.
Address groupsFor a link, the capture groups, tried in order, that hold the address it opens when clicked or tapped; 0 is the whole match. Only web, mail and telephone addresses open.

The group numbers count the pattern's parentheses from 1; 0 is the whole match. A profile that does not replace Markdown also keeps Markdown's own reading of the kinds its rules do not declare, such as its quote bars and the pairs of **.

Document attributes and conditional sections#

A Document attribute rule defines a value by name, and an Attribute reference rule (an inline rule with parts name and original) replaces a reference with it. A reference to an attribute no one has defined stays as written. A Conditional section keeps or drops the blocks between its lines, depending on whether the attributes it names are set. Attributes apply from where they are defined onwards.

A rule producing Settings for the next block recognizes a whole line that configures the block after it and shows nothing itself. Its parts and fixed attributes are given to that block: title, id, nodeType, language and hardbreaks have the meanings listed under Parts, and any other part is kept on the block, where a table, list or quote reads it.

Testing a profile#

At the bottom of the editor, Test Sample holds sample text (it starts as a heading and a line of text). Choose Check sample to see the nodes your rules make, indented as they nest. It says "No blocks recognized." when nothing matches.

Baseline#

A profile's baseline is its restore point: how it was when you created, duplicated or imported it. Reset to Baseline discards every change since then, after you confirm. Set as New Baseline saves the profile and makes its current state the restore point.

Saving is refused, with a message, if the profile replaces Markdown but has no end-of-line rule, if a pattern is unsafe and could hang the editor, or if the file cannot be written.

Outputs#

What a rule Produces: its name in the menu, then the name the profile file stores, whether block or inline rules can produce it, and the parts it reads. A rule may also name an output this list does not have, kept as Custom.

#### Text structure

OutputStored asKindReads
Heading 1heading1block
Heading 2heading2block
Heading 3heading3block
Heading 4heading4block
Heading 5heading5block
Heading 6heading6block
Paragraphparagraphblock
Horizontal rulethematicBreak or thematic_breakblock
End of linenewlineblock and inline
Heading (level from the rule)headingblocklevel

#### Lists

OutputStored asKindReads
Listlistblockordered, start
Bulleted list itemlistItemUnorderedblock
Numbered list itemlistItemOrderedblock
Checklist itemtaskListMarkerblock
Description list termdefinition_termblockterm, marker

#### Blocks

OutputStored asKindReads
Code blockcode_block or codeBlock or fencedCodeblocklanguage, content
Preformatted textliteral_blockblock
Raw HTMLhtml_blockblock
Equationmath_block or mathBlockblocknotation, content
Diagramdiagramblockformat, content
Tabletableblockcolumns, header, noHeader, format
Table row linetableRowblock

#### Boxes and quotes

OutputStored asKindReads
Quoteblockquoteblockattribution, citetitle
Quote line markerblockquoteMarkerblock
Admonition linealertMarkerblocktype
Admonition boxadmonitionblocktype, title
Sidebarsidebarblocktitle
Example boxexampleblocktitle
Collapsible sectiondetailsblocksummary, open
Group (no box)open_blockblock

#### Hidden and settings

OutputStored asKindReads
Comment (hidden)commentblock
Settings for the next blockblock_attributesblocknodeType, title, id, language, hardbreaks, sectionLabel, sectionLabelStart, presentation
Document attributeattribute_definitionblockname, value, unset
Conditional sectionconditionalblockcondition, conditionType, anyOf, allOf

#### Formatting

OutputStored asKindReads
Boldstronginline
Italicemphasisinline
Highlightmarkinline
Underlineunderlineinline
Strikethroughstrikethroughinline
Superscriptsuperscriptinline
Subscriptsubscriptinline
Inline codecodeSpan or codeinline
Keyboard keykeyboardinlinekeys
Line breakline_breakinline
Replacement texttextinlinecontent
Raw HTML (inline)html_inlineinlinecontent

#### Links and references

OutputStored asKindReads
Linklinkinlineurl, title, text
Web addressautolinkinline
Cross-referencecross_referenceinlinetargetID, label
Anchoranchorinlineid, label
Attribute referencesubstitutioninlinename, original
Footnotefootnote_definitioninlineid, text
Index termindex_terminlineprimary, secondary, tertiary

#### Media and maths

OutputStored asKindReads
Imageimageblock and inlineurl, alt, title
Videovideoblocksrc
Audioaudioblocksrc
Inline equationmath_inline or inlineMathinlinenotation, content

Parts#

Parts are the named pieces of a match that an output reads.

PartMeaning
allOfThe separator between names when all of them are needed, such as +.
altAn image's description, for readers who cannot see it.
anyOfThe separator between names when any one of them is enough, such as ,.
attributionWho said a quote, shown under it.
citetitleThe work a quote comes from, shown after the attribution.
columnsA table's column list, such as 1,2,1; its entries count the columns.
conditionThe attribute names the section depends on.
conditionTypedefined keeps the section when the attributes are set, undefined when they are not.
contentThe text itself, when it is not the whole match.
formatA diagram's engine (mermaid or vega-lite); for a table, which of its delimited formats the cells use.
hardbreaksWhen present, keeps the next block's single line breaks.
headerAny value but false makes a table's first row its header.
idA name: for the next block, the id cross-references point to; for a footnote, a name that lets later footnotes with no text of their own share its number.
keysThe keys to press, separated by commas.
labelThe text shown for a reference or anchor, in place of the target's own title.
languageA code block's programming language, used for its coloring.
levelThe heading level, from 1 to 6.
markerThe separator after the term, such as ::. A different marker nests a list inside the description.
nameThe attribute's name, in a definition or a reference.
nodeTypeMakes the next block into another output, by its name in the file.
noHeaderWhen present, a table has no header row.
notationThe maths notation: tex (the default) or latex.
opentrue shows a collapsible section open.
orderedtrue makes the list numbered.
originalThe reference as written, shown when the attribute is not defined.
presentationHow the next description list is shown: sideBySide puts terms and descriptions in two columns; questions numbers each term as a question, with its answer under it.
primaryThe index entry.
secondaryA sub-entry under the index entry.
sectionLabelA word the next heading's number follows, such as Appendix: such headings are counted on their own, Appendix A:.
sectionLabelStartThe first of those numbers: a letter (A) counts in letters, a number in numbers.
srcThe address of the video or audio file.
startThe number a numbered list starts at.
summaryThe line shown on a collapsible section while it is closed.
targetIDThe id the reference points to.
termThe term being described.
tertiaryA sub-entry under the secondary one.
textThe text shown, when the pattern captures more than that. A footnote's text follows the paragraph, table or list it is in, numbered.
titleA title: a box's heading, an image's or link's tooltip, or a caption above the next block.
typeThe kind of admonition, such as note, tip or warning.
unsetWhen present, the rule removes the attribute instead of defining it.
urlThe address a link or image points to.
valueThe attribute's value; references to attributes defined earlier are replaced in it.