|
1 | 1 | # Process admonitions and pass to cb.
|
2 | 2 | from __future__ import annotations
|
3 | 3 |
|
| 4 | +import re |
4 | 5 | from typing import TYPE_CHECKING, Callable, Sequence
|
5 | 6 |
|
6 | 7 | from markdown_it import MarkdownIt
|
|
14 | 15 | from markdown_it.utils import EnvType, OptionsDict
|
15 | 16 |
|
16 | 17 |
|
17 |
| -def _get_tag(params: str) -> tuple[str, str]: |
| 18 | +def _get_tag(params: str) -> tuple[List[str], str]: |
18 | 19 | """Separate the tag name from the admonition title."""
|
19 |
| - if not params.strip(): |
20 |
| - return "", "" |
21 | 20 |
|
22 |
| - tag, *_title = params.strip().split(" ") |
23 |
| - joined = " ".join(_title) |
| 21 | + params = params.strip() |
24 | 22 |
|
25 |
| - title = "" |
26 |
| - if not joined: |
27 |
| - title = tag.title() |
28 |
| - elif joined != '""': |
29 |
| - title = joined |
30 |
| - return tag.lower(), title |
| 23 | + if not params: |
| 24 | + return [""], "" |
| 25 | + |
| 26 | + match = re.match('^\s*([^"]+)\s+"(.*)"\S*$', params) |
| 27 | + if match: |
| 28 | + tokens = match.group(1) |
| 29 | + tags = tokens.strip().split(" ") |
| 30 | + title = match.group(2) |
| 31 | + return [tag.lower() for tag in tags], title |
| 32 | + else: |
| 33 | + tags = params.split(" ") |
| 34 | + return [tag.lower() for tag in tags], tags[0].title() |
31 | 35 |
|
32 | 36 |
|
33 | 37 | def _validate(params: str) -> bool:
|
@@ -125,12 +129,13 @@ def admonition(state: StateBlock, startLine: int, endLine: int, silent: bool) ->
|
125 | 129 | # this will prevent lazy continuations from ever going past our end marker
|
126 | 130 | state.lineMax = next_line
|
127 | 131 |
|
128 |
| - tag, title = _get_tag(params) |
| 132 | + tags, title = _get_tag(params) |
| 133 | + tag = tags[0] |
129 | 134 |
|
130 | 135 | token = state.push("admonition_open", "div", 1)
|
131 | 136 | token.markup = markup
|
132 | 137 | token.block = True
|
133 |
| - token.attrs = {"class": " ".join(["admonition", tag, *_extra_classes(markup)])} |
| 138 | + token.attrs = {"class": " ".join(["admonition", *tags, *_extra_classes(markup)])} |
134 | 139 | token.meta = {"tag": tag}
|
135 | 140 | token.content = title
|
136 | 141 | token.info = params
|
|
0 commit comments