Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/utils.py: 53%
81 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:07 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:07 +0000
1from __future__ import annotations
3from collections.abc import Callable
4from pathlib import Path
7class OptionsDict(dict):
8 """A dictionary, with attribute access to core markdownit configuration options."""
10 @property
11 def maxNesting(self) -> int:
12 """Internal protection, recursion limit."""
13 return self["maxNesting"]
15 @maxNesting.setter
16 def maxNesting(self, value: int):
17 self["maxNesting"] = value
19 @property
20 def html(self) -> bool:
21 """Enable HTML tags in source."""
22 return self["html"]
24 @html.setter
25 def html(self, value: bool):
26 self["html"] = value
28 @property
29 def linkify(self) -> bool:
30 """Enable autoconversion of URL-like texts to links."""
31 return self["linkify"]
33 @linkify.setter
34 def linkify(self, value: bool):
35 self["linkify"] = value
37 @property
38 def typographer(self) -> bool:
39 """Enable smartquotes and replacements."""
40 return self["typographer"]
42 @typographer.setter
43 def typographer(self, value: bool):
44 self["typographer"] = value
46 @property
47 def quotes(self) -> str:
48 """Quote characters."""
49 return self["quotes"]
51 @quotes.setter
52 def quotes(self, value: str):
53 self["quotes"] = value
55 @property
56 def xhtmlOut(self) -> bool:
57 """Use '/' to close single tags (<br />)."""
58 return self["xhtmlOut"]
60 @xhtmlOut.setter
61 def xhtmlOut(self, value: bool):
62 self["xhtmlOut"] = value
64 @property
65 def breaks(self) -> bool:
66 """Convert newlines in paragraphs into <br>."""
67 return self["breaks"]
69 @breaks.setter
70 def breaks(self, value: bool):
71 self["breaks"] = value
73 @property
74 def langPrefix(self) -> str:
75 """CSS language prefix for fenced blocks."""
76 return self["langPrefix"]
78 @langPrefix.setter
79 def langPrefix(self, value: str):
80 self["langPrefix"] = value
82 @property
83 def highlight(self) -> Callable[[str, str, str], str] | None:
84 """Highlighter function: (content, langName, langAttrs) -> escaped HTML."""
85 return self["highlight"]
87 @highlight.setter
88 def highlight(self, value: Callable[[str, str, str], str] | None):
89 self["highlight"] = value
92def read_fixture_file(path: str | Path) -> list[list]:
93 text = Path(path).read_text(encoding="utf-8")
94 tests = []
95 section = 0
96 last_pos = 0
97 lines = text.splitlines(keepends=True)
98 for i in range(len(lines)):
99 if lines[i].rstrip() == ".":
100 if section == 0:
101 tests.append([i, lines[i - 1].strip()])
102 section = 1
103 elif section == 1:
104 tests[-1].append("".join(lines[last_pos + 1 : i]))
105 section = 2
106 elif section == 2:
107 tests[-1].append("".join(lines[last_pos + 1 : i]))
108 section = 0
110 last_pos = i
111 return tests
114def _removesuffix(string: str, suffix: str) -> str:
115 """Remove a suffix from a string.
117 Replace this with str.removesuffix() from stdlib when minimum Python
118 version is 3.9.
119 """
120 if suffix and string.endswith(suffix):
121 return string[: -len(suffix)]
122 return string