@@ -16,35 +16,38 @@ def entity(state: StateInline, silent: bool) -> bool:
16
16
if state .src [pos ] != "&" :
17
17
return False
18
18
19
- if (pos + 1 ) < maximum :
20
- if state .src [pos + 1 ] == "#" :
21
- match = DIGITAL_RE .search (state .src [pos :])
22
- if match :
23
- if not silent :
24
- match1 = match .group (1 )
25
- code = (
26
- int (match1 [1 :], 16 )
27
- if match1 [0 ].lower () == "x"
28
- else int (match1 , 10 )
29
- )
30
- state .pending += (
31
- fromCodePoint (code )
32
- if isValidEntityCode (code )
33
- else fromCodePoint (0xFFFD )
34
- )
35
-
36
- state .pos += len (match .group (0 ))
37
- return True
38
-
39
- else :
40
- match = NAMED_RE .search (state .src [pos :])
41
- if match and match .group (1 ) in entities :
42
- if not silent :
43
- state .pending += entities [match .group (1 )]
44
- state .pos += len (match .group (0 ))
45
- return True
46
-
47
- if not silent :
48
- state .pending += "&"
49
- state .pos += 1
50
- return True
19
+ if pos + 1 >= maximum :
20
+ return False
21
+
22
+ if state .src [pos + 1 ] == "#" :
23
+ if match := DIGITAL_RE .search (state .src [pos :]):
24
+ if not silent :
25
+ match1 = match .group (1 )
26
+ code = (
27
+ int (match1 [1 :], 16 ) if match1 [0 ].lower () == "x" else int (match1 , 10 )
28
+ )
29
+
30
+ token = state .push ("text_special" , "" , 0 )
31
+ token .content = (
32
+ fromCodePoint (code )
33
+ if isValidEntityCode (code )
34
+ else fromCodePoint (0xFFFD )
35
+ )
36
+ token .markup = match .group (0 )
37
+ token .info = "entity"
38
+
39
+ state .pos += len (match .group (0 ))
40
+ return True
41
+
42
+ else :
43
+ if (match := NAMED_RE .search (state .src [pos :])) and match .group (1 ) in entities :
44
+ if not silent :
45
+ token = state .push ("text_special" , "" , 0 )
46
+ token .content = entities [match .group (1 )]
47
+ token .markup = match .group (0 )
48
+ token .info = "entity"
49
+
50
+ state .pos += len (match .group (0 ))
51
+ return True
52
+
53
+ return False
0 commit comments