From 6e17864cf53bbb0a99643b29865e5dfd47b7e8f4 Mon Sep 17 00:00:00 2001 From: Martin Schorfmann Date: Wed, 4 Oct 2023 21:39:27 +0200 Subject: [PATCH] Replace "axt" occurences with "atx" --- README.md | 16 ++++++++-------- benchmark/bench.py | 2 +- benchmark/cases/{axt.txt => atx.txt} | 0 src/mistune/block_parser.py | 18 +++++++++--------- src/mistune/list_parser.py | 2 +- tests/test_misc.py | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) rename benchmark/cases/{axt.txt => atx.txt} (100%) diff --git a/README.md b/README.md index 209320a..6e97cc2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/benchmark/bench.py b/benchmark/bench.py index 44cb228..379f401 100644 --- a/benchmark/bench.py +++ b/benchmark/bench.py @@ -112,7 +112,7 @@ def benchmarks(cases, count=100): if __name__ == '__main__': cases = [ # block - 'axt', + 'atx', 'setext', 'normal_ul', 'insane_ul', diff --git a/benchmark/cases/axt.txt b/benchmark/cases/atx.txt similarity index 100% rename from benchmark/cases/axt.txt rename to benchmark/cases/atx.txt diff --git a/src/mistune/block_parser.py b/src/mistune/block_parser.py index 2104d9d..1442c3f 100644 --- a/src/mistune/block_parser.py +++ b/src/mistune/block_parser.py @@ -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) @@ -56,7 +56,7 @@ class BlockParser(Parser): SPECIFICATION = { 'blank_line': r'(^[ \t\v\f]*\n)+', - 'axt_heading': r'^ {0,3}(?P#{1,6})(?!#+)(?P[ \t]*|[ \t]+.*?)$', + 'atx_heading': r'^ {0,3}(?P#{1,6})(?!#+)(?P[ \t]*|[ \t]+.*?)$', 'setex_heading': r'^ {0,3}(?P=|-){1,}[ \t]*$', 'fenced_code': ( r'^(?P {0,3})(?P`{3,}|~{3,})' @@ -77,7 +77,7 @@ class BlockParser(Parser): DEFAULT_RULES = ( 'fenced_code', 'indent_code', - 'axt_heading', + 'atx_heading', 'setex_heading', 'thematic_break', 'block_quote', @@ -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 diff --git a/src/mistune/list_parser.py b/src/mistune/list_parser.py index 6ce6baa..6a5e8dd 100644 --- a/src/mistune/list_parser.py +++ b/src/mistune/list_parser.py @@ -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']), diff --git a/tests/test_misc.py b/tests/test_misc.py index 62d4468..2d053fa 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -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'}, {