Skip to content

Commit e82d06e

Browse files
committed
♻️ REFACTOR: Move internal Rule/Delimiter to dataclass
In order to remove attr dependency
1 parent 063268b commit e82d06e

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

markdown_it/ruler.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ class Ruler
1818
from __future__ import annotations
1919

2020
from collections.abc import Callable, Iterable, MutableMapping
21+
from dataclasses import dataclass, field
2122
from typing import TYPE_CHECKING
2223

23-
import attr
24-
2524
if TYPE_CHECKING:
2625
from markdown_it import MarkdownIt
2726

@@ -51,12 +50,12 @@ def src(self, value: str) -> None:
5150
RuleFunc = Callable
5251

5352

54-
@attr.s(slots=True)
53+
@dataclass()
5554
class Rule:
56-
name: str = attr.ib()
57-
enabled: bool = attr.ib()
58-
fn: RuleFunc = attr.ib(repr=False)
59-
alt: list[str] = attr.ib()
55+
name: str
56+
enabled: bool
57+
fn: RuleFunc = field(repr=False)
58+
alt: list[str]
6059

6160

6261
class Ruler:

markdown_it/rules_inline/state_inline.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
from collections import namedtuple
44
from collections.abc import MutableMapping
5+
from dataclasses import dataclass
56
from typing import TYPE_CHECKING
67

7-
import attr
8-
98
from ..common.utils import isMdAsciiPunct, isPunctChar, isWhiteSpace
109
from ..ruler import StateBase
1110
from ..token import Token
@@ -14,35 +13,35 @@
1413
from markdown_it import MarkdownIt
1514

1615

17-
@attr.s(slots=True)
16+
@dataclass()
1817
class Delimiter:
1918
# Char code of the starting marker (number).
20-
marker: int = attr.ib()
19+
marker: int
2120

2221
# Total length of these series of delimiters.
23-
length: int = attr.ib()
22+
length: int
2423

2524
# An amount of characters before this one that's equivalent to
2625
# current one. In plain English: if this delimiter does not open
2726
# an emphasis, neither do previous `jump` characters.
2827
#
2928
# Used to skip sequences like "*****" in one step, for 1st asterisk
3029
# value will be 0, for 2nd it's 1 and so on.
31-
jump: int = attr.ib()
30+
jump: int
3231

3332
# A position of the token this delimiter corresponds to.
34-
token: int = attr.ib()
33+
token: int
3534

3635
# If this delimiter is matched as a valid opener, `end` will be
3736
# equal to its position, otherwise it's `-1`.
38-
end: int = attr.ib()
37+
end: int
3938

4039
# Boolean flags that determine if this delimiter could open or close
4140
# an emphasis.
42-
open: bool = attr.ib()
43-
close: bool = attr.ib()
41+
open: bool
42+
close: bool
4443

45-
level: bool = attr.ib(default=None)
44+
level: bool | None = None
4645

4746

4847
Scanned = namedtuple("Scanned", ["can_open", "can_close", "length"])

0 commit comments

Comments
 (0)