Skip to content

Commit 762637e

Browse files
committed
Clean needless try-excepts
1 parent 04a7c30 commit 762637e

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

markdown_it/rules_block/blockquote.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Block quotes
22
import logging
3-
from typing import Optional
43

54
from .state_block import StateBlock
65
from ..common.utils import isSpace
@@ -35,21 +34,16 @@ def blockquote(state: StateBlock, startLine: int, endLine: int, silent: bool):
3534
# set offset past spaces and ">"
3635
initial = offset = state.sCount[startLine] + 1
3736

38-
try:
39-
second_char_code: Optional[int] = state.srcCharCodeAt(pos)
40-
except IndexError:
41-
second_char_code = None
42-
4337
# skip one optional space after '>'
44-
if second_char_code == 0x20: # /* space */
38+
if state.srcCharCodeAt(pos) == 0x20: # /* space */
4539
# ' > test '
4640
# ^ -- position start of line here:
4741
pos += 1
4842
initial += 1
4943
offset += 1
5044
adjustTab = False
5145
spaceAfterMarker = True
52-
elif second_char_code == 0x09: # /* tab */
46+
elif state.srcCharCodeAt(pos) == 0x09: # /* tab */
5347
spaceAfterMarker = True
5448

5549
if (state.bsCount[startLine] + offset) % 4 == 3:
@@ -154,21 +148,16 @@ def blockquote(state: StateBlock, startLine: int, endLine: int, silent: bool):
154148
# set offset past spaces and ">"
155149
initial = offset = state.sCount[nextLine] + 1
156150

157-
try:
158-
next_char: Optional[int] = state.srcCharCodeAt(pos)
159-
except IndexError:
160-
next_char = None
161-
162151
# skip one optional space after '>'
163-
if next_char == 0x20: # /* space */
152+
if state.srcCharCodeAt(pos) == 0x20: # /* space */
164153
# ' > test '
165154
# ^ -- position start of line here:
166155
pos += 1
167156
initial += 1
168157
offset += 1
169158
adjustTab = False
170159
spaceAfterMarker = True
171-
elif next_char == 0x09: # /* tab */
160+
elif state.srcCharCodeAt(pos) == 0x09: # /* tab */
172161
spaceAfterMarker = True
173162

174163
if (state.bsCount[nextLine] + offset) % 4 == 3:

markdown_it/rules_block/heading.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
""" Atex heading (#, ##, ...) """
22
import logging
3-
from typing import Optional
43

54
from .state_block import StateBlock
65
from ..common.utils import isSpace
@@ -19,7 +18,7 @@ def heading(state: StateBlock, startLine: int, endLine: int, silent: bool):
1918
if state.sCount[startLine] - state.blkIndent >= 4:
2019
return False
2120

22-
ch: Optional[int] = state.srcCharCodeAt(pos)
21+
ch = state.srcCharCodeAt(pos)
2322

2423
# /* # */
2524
if ch != 0x23 or pos >= maximum:
@@ -28,18 +27,12 @@ def heading(state: StateBlock, startLine: int, endLine: int, silent: bool):
2827
# count heading level
2928
level = 1
3029
pos += 1
31-
try:
32-
ch = state.srcCharCodeAt(pos)
33-
except IndexError:
34-
ch = None
30+
ch = state.srcCharCodeAt(pos)
3531
# /* # */
3632
while ch == 0x23 and pos < maximum and level <= 6:
3733
level += 1
3834
pos += 1
39-
try:
40-
ch = state.srcCharCodeAt(pos)
41-
except IndexError:
42-
ch = None
35+
ch = state.srcCharCodeAt(pos)
4336

4437
if level > 6 or (pos < maximum and not isSpace(ch)):
4538
return False

0 commit comments

Comments
 (0)