|
9 | 9 | import logging |
10 | 10 | import os |
11 | 11 | import re |
| 12 | +from typing import Iterable |
| 13 | +from enum import Enum, auto |
12 | 14 |
|
13 | | -from .elements import Element, Heading, Inline, MDList, Table |
| 15 | +from .elements import Block, Element, Heading, Inline, MDList, Quote, Table |
14 | 16 |
|
15 | 17 | logger = logging.getLogger(__name__) |
16 | 18 |
|
@@ -53,6 +55,45 @@ def load(self, elements: list[Element]) -> None: |
53 | 55 | self._elements = elements |
54 | 56 |
|
55 | 57 |
|
| 58 | +class Alerts(Template): |
| 59 | + """ |
| 60 | + Alerts are a wrapper of the Quote object to provide |
| 61 | + support for the alerts Markdown extension. While |
| 62 | + quotes can be nested in each other, alerts cannot. |
| 63 | +
|
| 64 | + .. versionadded:: 2.4 |
| 65 | + Included for user convenience |
| 66 | +
|
| 67 | + :param Kind kind: |
| 68 | + the kind of alert; limited to: |
| 69 | +
|
| 70 | + - NOTE |
| 71 | + - TIP |
| 72 | + - IMPORTANT |
| 73 | + - WARNING |
| 74 | + - CAUTION |
| 75 | + :param str | Iterable[str | Inline | Block] message: |
| 76 | + the message you would like to show with the alert |
| 77 | + """ |
| 78 | + |
| 79 | + class Kind(Enum): |
| 80 | + NOTE = auto() |
| 81 | + TIP = auto() |
| 82 | + IMPORTANT = auto() |
| 83 | + WARNING = auto() |
| 84 | + CAUTION = auto() |
| 85 | + |
| 86 | + def __init__(self, kind: Kind, message: str | Iterable[str | Inline | Block]) -> None: |
| 87 | + self._kind = kind |
| 88 | + self._message = message |
| 89 | + |
| 90 | + def __str__(self) -> str: |
| 91 | + return str(Quote([f"[!{self._kind.name}]", self._message])) |
| 92 | + |
| 93 | + def __repr__(self) -> str: |
| 94 | + return f"Alerts(kind={self._kind!r},message={self._message!r})" |
| 95 | + |
| 96 | + |
56 | 97 | class CSVTable(Template): |
57 | 98 | """ |
58 | 99 | A CSV Table is a wrapper for the Table Block, |
@@ -141,7 +182,8 @@ class TableOfContents(Template): |
141 | 182 | def __init__(self, levels: range = range(2, 3)) -> None: |
142 | 183 | super().__init__() |
143 | 184 | self._levels: range = levels |
144 | | - logger.debug("New table of contents initialized with levels in %s", levels) |
| 185 | + logger.debug( |
| 186 | + "New table of contents initialized with levels in %s", levels) |
145 | 187 |
|
146 | 188 | def __str__(self) -> str: |
147 | 189 | """ |
|
0 commit comments