|
24 | 24 |
|
25 | 25 | from __future__ import annotations |
26 | 26 |
|
| 27 | +from collections.abc import Callable |
27 | 28 | import re |
28 | 29 | import sys |
29 | 30 | import warnings |
|
44 | 45 | """ |
45 | 46 |
|
46 | 47 |
|
47 | | -BLOCK_LEVEL_ELEMENTS: list[str] = [ |
| 48 | +class _BlockLevelElements(set): |
| 49 | + # ---------------------------------- |
| 50 | + # Methods common to `list` and `set` |
| 51 | + # ---------------------------------- |
| 52 | + def copy(self) -> set[str]: |
| 53 | + return _BlockLevelElements(super().copy()) |
| 54 | + |
| 55 | + def pop(self, index: int | None = None, /) -> str: |
| 56 | + if index is not None: |
| 57 | + warnings.warn("The index argument is deprecated and will be removed in the future", DeprecationWarning) |
| 58 | + try: |
| 59 | + return self.pop() |
| 60 | + except KeyError: |
| 61 | + warnings.warn("`pop` will raise a `KeyError` in the future", DeprecationWarning) |
| 62 | + raise IndexError("pop from an empty set") from None |
| 63 | + |
| 64 | + def remove(self, element: object) -> None: |
| 65 | + try: |
| 66 | + return self.remove(element) |
| 67 | + except KeyError: |
| 68 | + warnings.warn("`remove` will raise a `KeyError` in the future", DeprecationWarning) |
| 69 | + raise ValueError(f"{element!r} not in set") from None |
| 70 | + |
| 71 | + # -------------------------- |
| 72 | + # Methods specific to `list` |
| 73 | + # -------------------------- |
| 74 | + def append(self, element: str) -> None: |
| 75 | + warnings.warn("method `append` will be removed in the future", DeprecationWarning) |
| 76 | + self.add(element) |
| 77 | + |
| 78 | + def count(self, value: str) -> int: |
| 79 | + warnings.warn("method `count` will be removed in the future", DeprecationWarning) |
| 80 | + return 1 if value in self else 0 |
| 81 | + |
| 82 | + def extend(self, elements: list[str]) -> None: |
| 83 | + warnings.warn("method `extend` will be removed in the future", DeprecationWarning) |
| 84 | + self.update(elements) |
| 85 | + |
| 86 | + def index(self, value, start=0, stop=0, /) -> int: |
| 87 | + warnings.warn("method `index` will be removed in the future", DeprecationWarning) |
| 88 | + return 0 if value in self else -1 |
| 89 | + |
| 90 | + def insert(self, index: int, element: str) -> None: |
| 91 | + warnings.warn("method `insert` will be removed in the future", DeprecationWarning) |
| 92 | + self.add(element) |
| 93 | + |
| 94 | + def reverse(self) -> None: |
| 95 | + warnings.warn("method `reverse` will be removed in the future", DeprecationWarning) |
| 96 | + |
| 97 | + def sort(self, /, *, key: Callable | None = None, reverse: bool = False) -> None: |
| 98 | + warnings.warn("method `sort` will be removed in the future", DeprecationWarning) |
| 99 | + |
| 100 | + |
| 101 | +BLOCK_LEVEL_ELEMENTS: set[str] = _BlockLevelElements({ |
48 | 102 | # Elements which are invalid to wrap in a `<p>` tag. |
49 | 103 | # See https://w3c.github.io/html/grouping-content.html#the-p-element |
50 | 104 | 'address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', |
|
56 | 110 | 'math', 'map', 'noscript', 'output', 'object', 'option', 'progress', 'script', |
57 | 111 | 'style', 'summary', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'tr', 'video', |
58 | 112 | 'center' |
59 | | -] |
| 113 | +}) |
60 | 114 | """ |
61 | | -List of HTML tags which get treated as block-level elements. Same as the `block_level_elements` |
| 115 | +Set of HTML tags which get treated as block-level elements. Same as the `block_level_elements` |
62 | 116 | attribute of the [`Markdown`][markdown.Markdown] class. Generally one should use the |
63 | 117 | attribute on the class. This remains for compatibility with older extensions. |
64 | 118 | """ |
|
0 commit comments