Skip to content

Commit

Permalink
Merge pull request #359 from schorfma/atx-typo-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Oct 5, 2023
2 parents 44cc62b + 6e17864 commit 46043f7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -66,14 +66,14 @@ Tidelift will coordinate the fix and disclosure.
Here is the benchmark score on my computer. Check the `benchmark/bench.py` script.

```
mistune (3.0.0) - axt: 13.901472091674805ms
mistune (slow) - axt: 13.122797012329102ms
mistune (fast) - axt: 13.248443603515625ms
mistune (full) - axt: 15.445232391357422ms
markdown (3.3.7) - axt: 48.41303825378418ms
markdown2 (2.4.3) - axt: 379.30870056152344ms
mistletoe (0.8.2) - axt: 25.46215057373047ms
markdown_it (2.1.0) - axt: 42.37723350524902ms
mistune (3.0.0) - atx: 13.901472091674805ms
mistune (slow) - atx: 13.122797012329102ms
mistune (fast) - atx: 13.248443603515625ms
mistune (full) - atx: 15.445232391357422ms
markdown (3.3.7) - atx: 48.41303825378418ms
markdown2 (2.4.3) - atx: 379.30870056152344ms
mistletoe (0.8.2) - atx: 25.46215057373047ms
markdown_it (2.1.0) - atx: 42.37723350524902ms
mistune (3.0.0) - setext: 8.43048095703125ms
mistune (slow) - setext: 8.97979736328125ms
mistune (fast) - setext: 8.122920989990234ms
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bench.py
Expand Up @@ -112,7 +112,7 @@ def benchmarks(cases, count=100):
if __name__ == '__main__':
cases = [
# block
'axt',
'atx',
'setext',
'normal_ul',
'insane_ul',
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions src/mistune/block_parser.py
Expand Up @@ -20,7 +20,7 @@
from .list_parser import parse_list, LIST_PATTERN

_INDENT_CODE_TRIM = re.compile(r'^ {1,4}', flags=re.M)
_AXT_HEADING_TRIM = re.compile(r'(\s+|^)#+\s*$')
_ATX_HEADING_TRIM = re.compile(r'(\s+|^)#+\s*$')
_BLOCK_QUOTE_TRIM = re.compile(r'^ ?', flags=re.M)
_BLOCK_QUOTE_LEADING = re.compile(r'^ *>', flags=re.M)

Expand Down Expand Up @@ -56,7 +56,7 @@ class BlockParser(Parser):

SPECIFICATION = {
'blank_line': r'(^[ \t\v\f]*\n)+',
'axt_heading': r'^ {0,3}(?P<axt_1>#{1,6})(?!#+)(?P<axt_2>[ \t]*|[ \t]+.*?)$',
'atx_heading': r'^ {0,3}(?P<atx_1>#{1,6})(?!#+)(?P<atx_2>[ \t]*|[ \t]+.*?)$',
'setex_heading': r'^ {0,3}(?P<setext_1>=|-){1,}[ \t]*$',
'fenced_code': (
r'^(?P<fenced_1> {0,3})(?P<fenced_2>`{3,}|~{3,})'
Expand All @@ -77,7 +77,7 @@ class BlockParser(Parser):
DEFAULT_RULES = (
'fenced_code',
'indent_code',
'axt_heading',
'atx_heading',
'setex_heading',
'thematic_break',
'block_quote',
Expand Down Expand Up @@ -182,16 +182,16 @@ def markdown(text):
state.append_token(token)
return end_pos

def parse_axt_heading(self, m: Match, state: BlockState) -> int:
"""Parse token for AXT heading. An AXT heading is started with 1 to 6
def parse_atx_heading(self, m: Match, state: BlockState) -> int:
"""Parse token for ATX heading. An ATX heading is started with 1 to 6
symbol of ``#``."""
level = len(m.group('axt_1'))
text = m.group('axt_2').strip()
level = len(m.group('atx_1'))
text = m.group('atx_2').strip()
# remove last #
if text:
text = _AXT_HEADING_TRIM.sub('', text)
text = _ATX_HEADING_TRIM.sub('', text)

token = {'type': 'heading', 'text': text, 'attrs': {'level': level}, 'style': 'axt'}
token = {'type': 'heading', 'text': text, 'attrs': {'level': level}, 'style': 'atx'}
state.append_token(token)
return m.end() + 1

Expand Down
2 changes: 1 addition & 1 deletion src/mistune/list_parser.py
Expand Up @@ -93,7 +93,7 @@ def _parse_list_item(block, bullet, groups, token, state, rules):
pairs = [
('thematic_break', block.specification['thematic_break']),
('fenced_code', block.specification['fenced_code']),
('axt_heading', block.specification['axt_heading']),
('atx_heading', block.specification['atx_heading']),
('block_quote', block.specification['block_quote']),
('block_html', block.specification['block_html']),
('list', block.specification['list']),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_misc.py
Expand Up @@ -84,7 +84,7 @@ def test_ast_output(self):
'type': 'heading',
'children': [{'type': 'text', 'raw': 'h1'}],
'attrs': {'level': 1},
'style': 'axt',
'style': 'atx',
},
{'type': 'blank_line'},
{
Expand Down

0 comments on commit 46043f7

Please sign in to comment.