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

1from __future__ import annotations 

2 

3from collections.abc import Callable 

4from pathlib import Path 

5 

6 

7class OptionsDict(dict): 

8 """A dictionary, with attribute access to core markdownit configuration options.""" 

9 

10 @property 

11 def maxNesting(self) -> int: 

12 """Internal protection, recursion limit.""" 

13 return self["maxNesting"] 

14 

15 @maxNesting.setter 

16 def maxNesting(self, value: int): 

17 self["maxNesting"] = value 

18 

19 @property 

20 def html(self) -> bool: 

21 """Enable HTML tags in source.""" 

22 return self["html"] 

23 

24 @html.setter 

25 def html(self, value: bool): 

26 self["html"] = value 

27 

28 @property 

29 def linkify(self) -> bool: 

30 """Enable autoconversion of URL-like texts to links.""" 

31 return self["linkify"] 

32 

33 @linkify.setter 

34 def linkify(self, value: bool): 

35 self["linkify"] = value 

36 

37 @property 

38 def typographer(self) -> bool: 

39 """Enable smartquotes and replacements.""" 

40 return self["typographer"] 

41 

42 @typographer.setter 

43 def typographer(self, value: bool): 

44 self["typographer"] = value 

45 

46 @property 

47 def quotes(self) -> str: 

48 """Quote characters.""" 

49 return self["quotes"] 

50 

51 @quotes.setter 

52 def quotes(self, value: str): 

53 self["quotes"] = value 

54 

55 @property 

56 def xhtmlOut(self) -> bool: 

57 """Use '/' to close single tags (<br />).""" 

58 return self["xhtmlOut"] 

59 

60 @xhtmlOut.setter 

61 def xhtmlOut(self, value: bool): 

62 self["xhtmlOut"] = value 

63 

64 @property 

65 def breaks(self) -> bool: 

66 """Convert newlines in paragraphs into <br>.""" 

67 return self["breaks"] 

68 

69 @breaks.setter 

70 def breaks(self, value: bool): 

71 self["breaks"] = value 

72 

73 @property 

74 def langPrefix(self) -> str: 

75 """CSS language prefix for fenced blocks.""" 

76 return self["langPrefix"] 

77 

78 @langPrefix.setter 

79 def langPrefix(self, value: str): 

80 self["langPrefix"] = value 

81 

82 @property 

83 def highlight(self) -> Callable[[str, str, str], str] | None: 

84 """Highlighter function: (content, langName, langAttrs) -> escaped HTML.""" 

85 return self["highlight"] 

86 

87 @highlight.setter 

88 def highlight(self, value: Callable[[str, str, str], str] | None): 

89 self["highlight"] = value 

90 

91 

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 

109 

110 last_pos = i 

111 return tests 

112 

113 

114def _removesuffix(string: str, suffix: str) -> str: 

115 """Remove a suffix from a string. 

116 

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