Skip to content

Commit 7a5a614

Browse files
committed
docs(manual): Add Djot filters and improve a few sections
1 parent 7a7689f commit 7a5a614

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

examples/sile-and-djot.dj

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> "Djot (/dʒɑt/) is a light markup syntax.
44
> It derives most of its features from commonmark, but it fixes a few things
5-
> that make ommonmark's syntax complex and difficult to parse efficiently.
5+
> that make commonmark's syntax complex and difficult to parse efficiently.
66
> It is also much fuller-featured (...)"
77
^ From the [Djot website](https://djot.net/).
88

@@ -36,7 +36,7 @@ The core concepts in Djot mirror those of Markdown, featuring inline and block e
3636

3737
All ASCII punctuation characters (even those that have no special meaning in Djot) may be "backslash-escaped."
3838
Thus, `\*` is parsed and rendered as a literal \* character.
39-
Backslashes before characters other than ASCII punctuation characters are just treated as literal backslashes, except before a newline, and a space (or a tab) character.
39+
Backslashes before other characters are treated as literal backslashes, except before a newline, and a space (or a tab) character.
4040
We will get back to this later.
4141

4242
: Inline elements
@@ -61,13 +61,13 @@ The core concepts in Djot mirror those of Markdown, featuring inline and block e
6161

6262
## Attributes
6363

64-
Actually, let's start with attributes, as they have the same general syntax for both inline and block elements.
64+
Let's start with attributes, as they have the same general syntax for both inline and block elements.
6565

6666
Attributes are put inside curly braces.
67-
On inline elements, attributes are placed immediately after the element they are attached to, with no intervening whitespace.
67+
On inline elements, they are placed immediately after the element they are attached to, with no intervening whitespace.
6868
They may contain line breaks, and may be "stacked," in which case they are combined.
6969

70-
To attach attributes to a block-level element, put the attributes on the line immediately before the block.
70+
To attach attributes to a block-level element, put them on the line immediately before the block.
7171
Block attributes have the same syntax as inline attributes, but they must fit on one line.
7272
Repeated attribute specifiers can also be used, and the attributes accumulate.
7373

@@ -76,19 +76,24 @@ Inside the curly braces, the following syntax is possible:
7676
- `#foo` specifies an identifier, for referencing purposes.
7777

7878
An element may have only one identifier; if multiple identifiers are given, the last one is used.
79+
Identifiers shall be unique.
7980

8081
- `.foo` specifies a class, for styling purposes.
8182

8283
Multiple classes may be given in this way.
8384

8485
- `key="value"` or `key=value` specifies a key-value attribute.
8586

86-
Quotes are not needed when the value consists entirely of ASCII alphanumeric characters or `_` or `:` or `-`. Backslash escapes may be used inside quoted values.
87+
Quotes are not needed when the value consists of ASCII alphanumeric characters or `_` or `:` or `-`. Backslash escapes may be used inside quoted values.
8788

8889
- `?foo` and `!foo` specify a condition.
8990

9091
This is an extension specific to this converter, see §[](#djot-conditional-attributes).
9192

93+
- `:foo` and `:foo=value` specify an index entry.
94+
95+
This is an extension specific to this converter, see §[](#djot-index-entries-custom).
96+
9297
## Inline elements
9398

9499
### Spaces
@@ -226,7 +231,7 @@ You might notice a small difference between 2^10^{fake=false} and 2^10^{fake=tru
226231
```
227232
:::
228233

229-
There is another, likely more important, implication.
234+
There is another, more important, implication.
230235
This converter assumes that the content of a superscript or subscript consists of text, as it tries to use font features or text scaling techniques to render it.
231236

232237
[^djot-textsubsuper]: Refer to the *textsubsuper* package for details.
@@ -414,7 +419,6 @@ Another link to [the SILE website][sile].
414419
[sile]: https://sile-typesetter.org/
415420

416421
The reference label should be defined somewhere in the document.
417-
If the label is empty, then the link text is taken to be the reference label as well as the link text.
418422

419423
{#djot-cross-references}
420424
#### Cross-references
@@ -1314,31 +1318,35 @@ This is SILE and Djot at their best{custom-style="strong"}!
13141318
That's a fairly contrived way to obtain a bold text, but you get the underlying general idea.
13151319
This is one of the ways to use SILE commands in Djot.
13161320
While you could invoke _any_ SILE command with this feature, we recommend, though, to restrict it to styling.
1317-
Another more powerful way to leverage Djot with SILE’s full processing capabilities, and benefit from the best of both worlds, is to use the "raw" annotations, described in §[](#djot-raw-inlines) and §[](#djot-raw-blocks).
1321+
Another more powerful way to leverage Djot with SILE’s full processing capabilities, and benefit from the best of both worlds, is to use the "raw" annotations, described in §[](#djot-raw-inlines) and §[](#djot-raw-blocks); or filters, discussed in §[](#djot-configuration).
13181322

13191323

13201324
### Templates and variable substitution
13211325

13221326
[^:pumpernickel:]: Herbert _"Froggie"_ Pumpernickel{.smallcaps .nobreak}
13231327

13241328
Let's now pretend that you are writing an essay about some fictitious :pumpernickel:.
1329+
At this point, you know how to typeset that name in Djot syntax:
13251330

1326-
From the previous sections, you know how to typeset that name in Djot syntax:
1327-
`Herbert _"Froggie"_ Pumpernickel{.smallcaps .nobreak}`.
1331+
{custom-style=CodeBlock}
1332+
:::
1333+
```
1334+
Herbert _"Froggie"_ Pumpernickel{.smallcaps .nobreak}
1335+
```
1336+
:::
13281337

13291338
So far, so good...
13301339
But your problem is that this long name will appear a lot of times.
13311340
Repeating it is tedious and error-prone.
13321341
Would you appreciate defining it as a replaceable variable going by a much simpler name?
13331342

1334-
Well, Djot has the notion of a "symbol", a keyword surrounded by colon signs (§[](#djot-symbols)).
1335-
Although it was initially provisioned for "emojis", the default interpretation is now left to the rendering engine.
1343+
Djot has the notion of a "symbol", a keyword surrounded by colon signs (§[](#djot-symbols)).
1344+
The interpretation of such symbols is left to the rendering engine.
1345+
This converter uses them in non-conventional ways.
13361346

1337-
This converter for SILE is focussed on producing print-quality books, where so-called emojis play little part.
1338-
We are therefore going to use those symbols in a non-conventional way.
13391347
Back to our initial question, what if you could just type `:pumpernickel:` and have it automatically expanded?
13401348

1341-
Since it's possible to have unused footnote definitions, let's craft one as shown hereafter, with its reference identifier being the same as our targeted variable.
1349+
It’s possible to define footnotes without ever using them, so let's first craft one here, with same reference identifier as our target variable.
13421350

13431351
{custom-style=CodeBlock}
13441352
:::
@@ -1347,7 +1355,8 @@ Since it's possible to have unused footnote definitions, let's craft one as show
13471355
```
13481356
:::
13491357

1350-
When encountering a symbol, this converter looks for such a footnote and expands its content.
1358+
When encountering a symbol, the converter looks for such a footnote and expands its content.
1359+
13511360
It works with inline elements as shown above, but also with full blocks, provided the symbol is the only element in a paragraph of its own.
13521361
Of course, these pseudo-footnotes[^djot-pseudo-footnotes] can in turn contain symbols, which get replaced too.
13531362

@@ -1441,11 +1450,11 @@ Optionally, an `indexed-⟨index⟩` attribute may be provided to define the tex
14411450
```
14421451
:::
14431452

1453+
{#djot-index-entries-custom}
14441454
#### Shortcut syntax for indexing entries
14451455

14461456
The syntax above is fully valid Djot and thus portable to other converters.
14471457
However, it tends to be somewhat verbose and less than _lightweight_ in practice.
1448-
14491458
For convenience, our Djot implementation also supports a more compact, non-standard syntax that is easier to type.
14501459

14511460
{custom-style=CodeBlock}
@@ -1494,3 +1503,11 @@ For document classes supporting it (in particular, the *resilient* book class),
14941503
\include[src=somefile.dj, shift_headings=-1]
14951504
```
14961505
:::
1506+
1507+
For developers, the converter also accepts a `filter` option, whose value is the name of a Lua script (with or without the `.lua` extension).
1508+
This script is loaded in a sandboxed environment and must return a table of filters in the form expected by the **djot.lua** library.
1509+
1510+
Filters traverse the Djot AST and rewrite it, following the transformation rules you define.
1511+
They can be useful to customize the conversion process in arbitrary ways --- adding features, modifying formatting, or transforming content structure in ways this converter doesn't provide out of the box.
1512+
1513+
In other terms, in addition to raw annotations, custom styles and programmatic symbols, filters are another way to adapt this converter to your specific needs.

examples/sile-and-markdown.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,14 @@ This is one of the ways to use SILE commands in Djot.
13111311
While you could invoke _any_ SILE command with this feature, we recommend, though, to restrict it to styling.
13121312
Another more powerful way to leverage Djot with SILE’s full processing capabilities, and benefit from the best of both worlds, is to use the "raw" annotations, described in §[](#markdown-raw-inlines) and §[](#markdown-raw-blocks).
13131313

1314+
::: {custom-style=Difference}
1315+
![](./examples/manicule.svg){height=1.3ex} **Main differences with Djot**
1316+
1317+
- Only works on divs and spans (versus almost any element in Djot).
1318+
1319+
:::
1320+
1321+
13141322
### Index entries
13151323

13161324
Markdown does not provide a built-in syntax for marking index entries within the text.

0 commit comments

Comments
 (0)