Skip to content

Commit c2a1539

Browse files
committed
directives
1 parent d0901aa commit c2a1539

17 files changed

Lines changed: 170 additions & 27 deletions

File tree

docs/assets/icons/scissors.svg

Lines changed: 3 additions & 0 deletions
Loading

docs/assets/js/page.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,30 @@ export function ready() {
66
if (pop) { pop.hidePopover(); }
77
});
88
});
9+
10+
if (!window.scrollPositions) {
11+
window.scrollPositions = {};
12+
}
13+
window.addEventListener("turbo:before-cache", preserveScroll)
14+
window.addEventListener("turbo:before-render", restoreScroll)
15+
window.addEventListener("turbo:render", restoreScroll)
16+
}
17+
18+
function preserveScroll () {
19+
document.querySelectorAll("[data-preserve-scroll]").forEach((element) => {
20+
scrollPositions[element.id] = element.scrollTop;
21+
})
22+
}
23+
24+
function restoreScroll (event) {
25+
document.querySelectorAll("[data-preserve-scroll]").forEach((element) => {
26+
element.scrollTop = scrollPositions[element.id];
27+
})
28+
29+
if (!event.detail.newBody) return
30+
// event.detail.newBody is the body element to be swapped in.
31+
// https://turbo.hotwired.dev/reference/events
32+
event.detail.newBody.querySelectorAll("[data-preserve-scroll]").forEach((element) => {
33+
element.scrollTop = scrollPositions[element.id];
34+
})
935
}

docs/content/directives/divs.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Divs
3+
icon: icons/blocks.svg
4+
---
5+
6+
This is a generic wrapper with HTML classes to customize your documents.
7+
8+
Instead of a title, the text after the name will be added as classes:
9+
10+
```md
11+
::: div my-class another-class
12+
Any markdown content
13+
:::
14+
```
15+
16+
will render as
17+
18+
```html
19+
<div class="my-class another-class">
20+
<p>Any markdown content</p>
21+
</div>
22+
```

docs/content/directives/figures.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Figures
3+
icon: icons/image.svg
4+
---
5+
6+
The Markdown syntax doesn't provide native support for image captions, but you can use a `::: figure` block:
7+
8+
:::: div example
9+
10+
```markdown
11+
::: figure | Image caption
12+
![Alt text](/assets/images/image.png)
13+
:::
14+
```
15+
16+
::: figure | Image caption
17+
![Alt text](/assets/images/image.png)
18+
:::
19+
::::
20+

docs/content/directives/index.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Directives
3+
---
4+
5+
WriteADoc add to the common markdwown syntax some popular extensions it calls "directives". A directive starts and end with at least three periods `:::` and a name:
6+
7+
```markdown
8+
::: name | Some text
9+
:option1:=value1
10+
11+
Markdown content
12+
:::
13+
```
14+
15+
The `|` after the name is optional
16+
17+
## Nested directives
18+
19+
You can nest directives to add, for example, an admonition inside an div. To do so just use more ":" to the outer directive:
20+
21+
```md
22+
:::: div wrapper
23+
24+
::: note
25+
Hello
26+
:::
27+
28+
::::
29+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,13 @@ Tab 1 content
7474
Tab 2 should be selected by default.
7575
:::
7676
```
77+
78+
::: tab | Tab 1 title
79+
Tab 1 content
80+
:::
81+
82+
::: tab | Tab 2 title
83+
:select: True
84+
85+
Tab 2 should be selected by default.
86+
:::

docs/content/markdown.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/content/markdown/html.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ When the markdown attribute is set to "block", the parser will force block behav
6666

6767
The content of a block element is parsed into block-level content. In other words, the text is rendered as paragraphs, headers, lists, blockquotes, etc. Any inline syntax within those elements is processed as well.
6868

69-
/// example | Forced "block" markdown parsing
69+
:::: div example
70+
**Example: Forced "block" markdown parsing**
7071

7172
```md
7273
<section markdown="block">
@@ -93,16 +94,14 @@ renders as:
9394
</section>
9495
```
9596

96-
///
97-
98-
<!-- -->
97+
::::
9998

100-
/// warning
99+
::: warning
101100
Forcing elements to be parsed as `block` elements when they are not by default could result in invalid HTML.
102101

103102
For example, one could force a `<p>` element to be nested within another `<p>` element. In most cases, it is
104103
recommended to use the default behavior of `markdown="1"`.
105-
///
104+
:::
106105

107106

108107
### `markdown="span"`
@@ -111,7 +110,8 @@ When the markdown attribute is set to "span", the parser will force span behavio
111110

112111
The content of a span element is not parsed into block-level content. In other words, the content will not be rendered as paragraphs, headers, etc. Only inline syntax will be rendered, such as links, strong, emphasis, etc.
113112

114-
/// example | Forced "span" markdown parsing
113+
:::: div example
114+
**Example: Forced "span" markdown parsing**
115115

116116
```md
117117
<div markdown="span">
@@ -127,14 +127,15 @@ renders as:
127127
</div>
128128
```
129129

130-
///
130+
::::
131131

132132

133133
## Nesting
134134

135135
When nesting multiple levels of raw HTML elements, a markdown attribute must be defined for each block-level element. For any block-level element that does not have a markdown attribute, everything inside that element is ignored, including child elements with markdown attributes.
136136

137-
/// example | Markdown in nested HTML
137+
:::: div example
138+
**Example: Markdown in nested HTML
138139

139140
```md
140141
<article id="my-article" markdown="1">
@@ -175,3 +176,4 @@ renders as:
175176
</section>
176177
</article>
177178
```
179+
::::

docs/docs.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]
1414
},
1515
{
16-
"path": "markdown.md",
16+
"title": "Markdown",
1717
"pages": [
1818
"markdown/blocks.md",
1919
"markdown/formatting.md",
@@ -29,12 +29,19 @@
2929
},
3030
"markdown/code.md",
3131
"markdown/tables.md",
32-
"markdown/admonitions.md",
3332
"markdown/attributes.md",
34-
"markdown/tabs.md",
3533
# "markdown/html.md",
3634
],
3735
},
36+
{
37+
"path": "directives/index.md",
38+
"pages": [
39+
"directives/admonitions.md",
40+
"directives/figures.md",
41+
"directives/tabs.md",
42+
"directives/divs.md",
43+
],
44+
},
3845
"autodoc.md",
3946
"languages.md",
4047
"versions.md",

0 commit comments

Comments
 (0)