Fenced blocks¶
blocks
¶
The fenced QVR blocks of a Markdown document.
A fenced block opens with a line of three backticks and qvr (or R,
the closest lexer GitHub offers, which the root README uses for QVR),
possibly indented inside a tabbed section, and closes with three backticks at
the same indentation. An HTML comment on the line before the opening fence
sets the block's compile mode:
<!-- compile: false, because REASON -->: an illustrative fragment, not code. The reason says why the fragment cannot be a module (a lone statement shown outside the declaration that would hold it, say); the documentation gate requires one on every such fragment.<!-- compile: cumulative -->and<!-- compile: qiec-cumulative -->: the block continues every earlier cumulative block of the document.<!-- compile: qiec -->,<!-- compile: standalone -->: a complete module on its own.<!-- compile: refused "TEXT" -->: a complete module that is refused, shown to illustrate a diagnostic. The documentation gate compiles it and requires an error whose message containsTEXT.<!-- compile: file PATH -->: the filePATH(sigs.qvr,worlds/boolean.qvr) of the document's package. A document's file blocks are the modules of one package, and each is checked as a module of that package, so the blocks may import each other, declare holes, and link them.- no marker: a complete module on its own in an ordinary document; in a
literate
.qvr.mdmodule, part of the module the document tangles to, so the mode iscumulative.
A fence written ```qvr example holds the steps of an example
(let and expect lines): it is a test of the document's module, not
part of its code, and its mode is example. A block whose body is a single
--8<-- "docs/examples/....qvr" line includes a corpus file for display.
Every reader of fenced QVR blocks (the literate tangler, qvr migrate,
and the documentation gate) scans with scan_blocks, so they agree on which
blocks a document has and what each is.
FENCE
module-attribute
¶
FENCE = re.compile('^(?P<indent>[ \\t]*)```(?:qvr|R)(?P<example> example)?\\n(?P<body>.*?)^(?P=indent)```', re.M | re.S)
A fenced QVR block: its indentation, whether it is an example, and its body.
MARKER
module-attribute
¶
MARKER = re.compile('<!--\\s*compile:\\s*(?:(false|standalone|cumulative|qiec|qiec-cumulative)|file\\s+(?P<path>[A-Za-z0-9_][A-Za-z0-9_./-]*\\.qvr)|refused\\s+"(?P<refusal>[^"]+)")(?:\\s*,\\s*because\\s+(?P<reason>.*?))?\\s*-->')
The compile-mode marker on the line before a fence: a mode, file and
the package path of the file the block is, or refused and the text its
diagnostic contains, with the reason a false marker gives after
because.
INCLUDE
module-attribute
¶
A block whose whole body includes a corpus file.
CUMULATIVE_MODES
module-attribute
¶
The modes whose blocks continue the document's earlier cumulative blocks.
Mode
¶
Mode = Literal['false', 'standalone', 'cumulative', 'qiec', 'qiec-cumulative', 'example', 'file', 'refused']
A block's compile mode.
FencedBlock
didactic-model
¶
FencedBlock(*, line: int, mode: Mode, indent: str, start: int, end: int, body: str, include: str = '', reason: str = '', path: str = '', refusal: str = '')
Bases: Model
One fenced QVR block of a Markdown document.
| PARAMETER | DESCRIPTION |
|---|---|
line
|
The 1-based line of the opening fence.
TYPE:
|
mode
|
The block's compile mode.
TYPE:
|
indent
|
The fence's indentation, stripped from every body line.
TYPE:
|
start
|
The character offset of the body in the document.
TYPE:
|
end
|
The character offset one past the body.
TYPE:
|
body
|
The body with the indentation removed.
TYPE:
|
include
|
The included corpus path, or empty.
TYPE:
|
reason
|
The reason its
TYPE:
|
path
|
The package path of a
TYPE:
|
refusal
|
The text a
TYPE:
|
first_body_line
property
¶
The 1-based document line of the body's first line.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The line after the opening fence. |
dedent
¶
Strip a fence's indentation from every line of its body.
| PARAMETER | DESCRIPTION |
|---|---|
indent
|
The fence's indentation.
TYPE:
|
body
|
The body as written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The body with |
Source code in src/quivers/dsl/literate/blocks.py
indent_body
¶
Indent every non-blank line of a body by a fence's indentation.
| PARAMETER | DESCRIPTION |
|---|---|
indent
|
The fence's indentation.
TYPE:
|
body
|
A dedented body.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The body as it is written inside the fence. |
Source code in src/quivers/dsl/literate/blocks.py
marker_before
¶
marker_before(text: str, fence_start: int) -> Mode | None
The compile-mode marker on the line before a fence, if any.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The document.
TYPE:
|
fence_start
|
The offset of the fence's line.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Mode | None
|
The marked mode, or None for an unmarked block. |
Source code in src/quivers/dsl/literate/blocks.py
marker_refusal_before
¶
The diagnostic text a refused marker before a fence names.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The document.
TYPE:
|
fence_start
|
The offset of the fence's line.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The text, or empty when the block is not marked |
Source code in src/quivers/dsl/literate/blocks.py
marker_path_before
¶
The package path a file marker before a fence names.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The document.
TYPE:
|
fence_start
|
The offset of the fence's line.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The path, or empty when the block is not marked |
Source code in src/quivers/dsl/literate/blocks.py
marker_reason_before
¶
The reason a compile: false marker before a fence gives.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The document.
TYPE:
|
fence_start
|
The offset of the fence's line.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The text after |
Source code in src/quivers/dsl/literate/blocks.py
scan_blocks
¶
scan_blocks(text: str, *, literate: bool) -> tuple[FencedBlock, ...]
Find the fenced QVR blocks of a Markdown document.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The document.
TYPE:
|
literate
|
Whether the document is a literate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[FencedBlock, ...]
|
The blocks in document order. |