Skip to content

Commit 4827cbf

Browse files
authored
♻️ REFACTOR: Remove AttrDict (#181)
This is no longer used is core or mdit-py-plugins, instead standard dictionaries are used.
1 parent 934eb90 commit 4827cbf

File tree

6 files changed

+7
-37
lines changed

6 files changed

+7
-37
lines changed

markdown_it/common/entities.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
"""HTML5 entities map: { name -> characters }."""
22
import html.entities
33

4-
from markdown_it.utils import AttrDict
5-
6-
7-
DATA = {name.rstrip(";"): chars for name, chars in html.entities.html5.items()}
8-
9-
entities = AttrDict(DATA)
4+
entities = {name.rstrip(";"): chars for name, chars in html.entities.html5.items()}

markdown_it/common/utils.py

-10
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ def charCodeAt(src: str, pos: int) -> Any:
2222
return None
2323

2424

25-
# function _class(obj) { return Object.prototype.toString.call(obj); }
26-
27-
28-
def isString(obj: object) -> bool:
29-
return isinstance(obj, str)
30-
31-
32-
has = hasattr
33-
34-
3525
# Merge objects
3626
#
3727
def assign(obj):

markdown_it/rules_block/list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ def list_block(state: StateBlock, startLine: int, endLine: int, silent: bool):
200200
while pos < maximum:
201201
ch = state.srcCharCode[pos]
202202

203-
if ch == 0x09:
203+
if ch == 0x09: # \t
204204
offset += 4 - (offset + state.bsCount[nextLine]) % 4
205-
elif ch == 0x20:
205+
elif ch == 0x20: # \s
206206
offset += 1
207207
else:
208208
break

markdown_it/rules_inline/entity.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33

44
from ..common.entities import entities
5-
from ..common.utils import has, isValidEntityCode, fromCodePoint
5+
from ..common.utils import isValidEntityCode, fromCodePoint
66
from .state_inline import StateInline
77

88
DIGITAL_RE = re.compile(r"^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));", re.IGNORECASE)
@@ -42,7 +42,7 @@ def entity(state: StateInline, silent: bool):
4242
else:
4343
match = NAMED_RE.search(state.src[pos:])
4444
if match:
45-
if has(entities, match.group(1)):
45+
if match.group(1) in entities:
4646
if not silent:
4747
state.pending += entities[match.group(1)]
4848
state.pos += len(match.group(0))

markdown_it/utils.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Union
2+
from typing import Callable, List, Optional, Union
33

44

55
class OptionsDict(dict):
@@ -87,21 +87,6 @@ def highlight(self, value: Optional[Callable[[str, str, str], str]]):
8787
self["highlight"] = value
8888

8989

90-
if TYPE_CHECKING:
91-
AttrDict = Any
92-
else:
93-
94-
class AttrDict(dict):
95-
def __init__(self, *args, **kwargs):
96-
super(AttrDict, self).__init__(*args, **kwargs)
97-
self.__dict__ = self
98-
99-
# recursively apply to all nested dictionaries
100-
for key, item in list(self.items()):
101-
if isinstance(item, dict):
102-
self[key] = AttrDict(item)
103-
104-
10590
def read_fixture_file(path: Union[str, Path]) -> List[list]:
10691
text = Path(path).read_text(encoding="utf-8")
10792
tests = []

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ project_urls =
3030
[options]
3131
packages = find:
3232
install_requires =
33-
mdurl
3433
attrs>=19,<22
34+
mdurl~=0.1
3535
typing_extensions>=3.7.4;python_version<'3.8'
3636
python_requires = ~=3.6
3737
include_package_data = True

0 commit comments

Comments
 (0)