Skip to content

Commit 2c6d819

Browse files
committed
Multiline callouts
1 parent 6222ed0 commit 2c6d819

File tree

7 files changed

+94
-5
lines changed

7 files changed

+94
-5
lines changed

dactyl/dactyl_build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def main(cli_args, config):
539539
exit("FATAL: --vars value was improperly formatted: %s" % repr(e))
540540

541541
if cli_args.title:
542-
target.gain_keys({"display_name": cli_args.title})
542+
target.gain_fields({"display_name": cli_args.title})
543543

544544
if not cli_args.no_cover and not target.data.get("no_cover", False):
545545
target.add_cover()

dactyl/filter_callouts.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
]
2020
DEFAULT_CALLOUT_CLASS = "dactyl-callout"
2121

22+
from bs4.element import Tag
23+
2224
def filter_soup(soup, currentpage={}, config={}, **kwargs):
2325
"""
2426
Find patterns that look like callouts, for example **Note:**, and add
@@ -38,4 +40,11 @@ def filter_soup(soup, currentpage={}, config={}, **kwargs):
3840
if not c.previous_sibling: #This callout starts a block
3941
callout_type = c.string.replace(":","").lower()
4042
if callout_type in callout_classes:
41-
c.parent["class"] = [callout_base_class, callout_type]
43+
if (c.parent.parent.name == "blockquote" and Tag not in
44+
[type(u) for u in c.parent.previous_siblings]):
45+
# Special case for blockquotes, to allow multiline callouts.
46+
# First element of BQ must start with a callout keyword
47+
callout_el = c.parent.parent
48+
else:
49+
callout_el = c.parent
50+
callout_el["class"] = [callout_base_class, callout_type]

dactyl/target.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ def es_index_name(self):
124124

125125
def add_cover(self):
126126
"""
127-
Add the default cover page to the pagelist where self.load_pages()
128-
will find it.
127+
Instantiate the default cover page so self.load_pages() can include it.
129128
"""
130129
coverpage_data = self.config["cover_page"]
131130
coverpage_data["targets"] = [self.name]

dactyl/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.10.0-a123'
1+
__version__ = '0.10.0-a129'

examples/content/filter-examples/callouts.md

+42
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,45 @@ In order to use callouts, the page (or target) has to have the `callouts` filter
2525
|-------|-------|
2626
| **Warning:** Callout syntax in table cells is weird. | So it's probably best not to do that. |
2727
| Probably. | **Caution:** It could maybe work better with better CSS. |
28+
29+
> **Tip:** Multiline callouts with blockquotes are now possible.
30+
>
31+
> - Do this to include bulleted lists.
32+
> - Or other types of lists.
33+
>
34+
35+
If you have a callout word like **tip** bolded mid-paragraph, it should not become a callout.
36+
37+
> Please **note** that this also applies to blockquotes.
38+
39+
There is a difficult edge case for blockquotes where a paragraph other than the first one starts with a callout keyword:
40+
41+
> This is the start of a blockquote that is not, itself, a callout.
42+
>
43+
> **Note:** This callout occurs in the middle of a blockquote.
44+
>
45+
> But the blockquote containing it is not, itself, a callout.
46+
47+
Also, note that you can cannot use code fences in blockquotes.
48+
49+
> **Caution:** Code fences in blockquotes don't work right.
50+
>
51+
> ```js
52+
> if (true) {
53+
> console.log('this line of code should be indented');
54+
> }
55+
> ```
56+
>
57+
> The code fence gets treated as inlined code text instead. This is a limitation of Python-Markdown.
58+
59+
You can, however, use indented code blocks in blockquotes:
60+
61+
> **Tip:** To get a proper code block in a blockquote, provide a single
62+
> line of just the blockquote intro `>`, and indent the code block 5 spaces.
63+
>
64+
> print("Hello world!")
65+
> if True:
66+
> print("Note that extra spaces beyond the initial 5 carry over.")
67+
>
68+
> To continue the block quote afterwords, leave a near-blank line similarly.
69+
> Do not use code fences in a blockquote: they don't work as expected.

releasenotes.md

+20
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,26 @@ This release improves several aspects of OpenAPI (Swagger) specification parsing
212212

213213
However, OpenAPI spec parsing should still be considered experimental.
214214

215+
### Multiline Callouts
216+
217+
The built-in callouts filter now supports multi-line callouts using Markdown's blockquote syntax. A blockquote must be set off from paragraph text by blank lines before and after. Within the blockquote, each line must start with `> `. (The space is optional but recommended.) For example:
218+
219+
```md
220+
Some paragraph text.
221+
222+
> **Tip:** This begins a multiline callout.
223+
>
224+
> - It can have lists.
225+
> - Indentation does not count the space in the `> ` as part of its
226+
> requirements, so things that would normally need to be indented 4 spaces
227+
> must be indented 5 instead.
228+
> - That's just Markdown syntax for you.
229+
230+
More paragraph text
231+
```
232+
233+
Build the [examples](examples/) to see it in action and to see some samples of specific edge cases.
234+
215235
## Bug Fixes and Other Cleanup
216236

217237
- `--skip_preprocessor` (when using a config file) works again. It had been broken since v0.40.0.

tests/unit_target.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
import unittest
3+
import os
4+
5+
from unit_shared import *
6+
7+
from dactyl.target import DactylTarget
8+
9+
10+
class TestDactylPage(unittest.TestCase):
11+
def test_target_from_pages(self):
12+
files=["../examples/content/filter-examples/badges.md","../examples/content/filter-examples/buttonize.md"]
13+
t = DactylTarget(config=mockconfig, inpages=files)
14+
t.load_pages()
15+
16+
17+
18+
if __name__ == '__main__':
19+
unittest.main()

0 commit comments

Comments
 (0)