diff --git a/src/mistune/block_parser.py b/src/mistune/block_parser.py index 1ed79ec..2104d9d 100644 --- a/src/mistune/block_parser.py +++ b/src/mistune/block_parser.py @@ -1,5 +1,5 @@ import re -from typing import Optional, List, Tuple +from typing import Optional, List, Tuple, Match from .util import ( unikey, escape_url, @@ -109,18 +109,18 @@ def __init__( name: getattr(self, 'parse_' + name) for name in self.SPECIFICATION } - def parse_blank_line(self, m: re.Match, state: BlockState) -> int: + def parse_blank_line(self, m: Match, state: BlockState) -> int: """Parse token for blank lines.""" state.append_token({'type': 'blank_line'}) return m.end() - def parse_thematic_break(self, m: re.Match, state: BlockState) -> int: + def parse_thematic_break(self, m: Match, state: BlockState) -> int: """Parse token for thematic break, e.g. ``
`` tag in HTML.""" state.append_token({'type': 'thematic_break'}) # $ does not count '\n' return m.end() + 1 - def parse_indent_code(self, m: re.Match, state: BlockState) -> int: + def parse_indent_code(self, m: Match, state: BlockState) -> int: """Parse token for code block which is indented by 4 spaces.""" # it is a part of the paragraph end_pos = state.append_paragraph() @@ -134,7 +134,7 @@ def parse_indent_code(self, m: re.Match, state: BlockState) -> int: state.append_token({'type': 'block_code', 'raw': code, 'style': 'indent'}) return m.end() - def parse_fenced_code(self, m: re.Match, state: BlockState) -> Optional[int]: + def parse_fenced_code(self, m: Match, state: BlockState) -> Optional[int]: """Parse token for fenced code block. A fenced code block is started with 3 or more backtick(`) or tilde(~). @@ -182,7 +182,7 @@ def markdown(text): state.append_token(token) return end_pos - def parse_axt_heading(self, m: re.Match, state: BlockState) -> int: + def parse_axt_heading(self, m: Match, state: BlockState) -> int: """Parse token for AXT heading. An AXT heading is started with 1 to 6 symbol of ``#``.""" level = len(m.group('axt_1')) @@ -195,7 +195,7 @@ def parse_axt_heading(self, m: re.Match, state: BlockState) -> int: state.append_token(token) return m.end() + 1 - def parse_setex_heading(self, m: re.Match, state: BlockState) -> Optional[int]: + def parse_setex_heading(self, m: Match, state: BlockState) -> Optional[int]: """Parse token for setex style heading. A setex heading syntax looks like: .. code-block:: markdown @@ -216,7 +216,7 @@ def parse_setex_heading(self, m: re.Match, state: BlockState) -> Optional[int]: if m: return self.parse_method(m, state) - def parse_ref_link(self, m: re.Match, state: BlockState) -> Optional[int]: + def parse_ref_link(self, m: Match, state: BlockState) -> Optional[int]: """Parse link references and save the link information into ``state.env``. Here is an example of a link reference: @@ -282,7 +282,7 @@ def parse_ref_link(self, m: re.Match, state: BlockState) -> Optional[int]: state.env['ref_links'][key] = data return end_pos - def extract_block_quote(self, m: re.Match, state: BlockState) -> Tuple[str, int]: + def extract_block_quote(self, m: Match, state: BlockState) -> Tuple[str, int]: """Extract text and cursor end position of a block quote.""" # cleanup at first to detect if it is code block @@ -349,7 +349,7 @@ def extract_block_quote(self, m: re.Match, state: BlockState) -> Tuple[str, int] # treated as 4 spaces return expand_tab(text), end_pos - def parse_block_quote(self, m: re.Match, state: BlockState) -> int: + def parse_block_quote(self, m: Match, state: BlockState) -> int: """Parse token for block quote. Here is an example of the syntax: .. code-block:: markdown @@ -374,14 +374,14 @@ def parse_block_quote(self, m: re.Match, state: BlockState) -> int: state.append_token(token) return state.cursor - def parse_list(self, m: re.Match, state: BlockState) -> int: + def parse_list(self, m: Match, state: BlockState) -> int: """Parse tokens for ordered and unordered list.""" return parse_list(self, m, state) - def parse_block_html(self, m: re.Match, state: BlockState) -> Optional[int]: + def parse_block_html(self, m: Match, state: BlockState) -> Optional[int]: return self.parse_raw_html(m, state) - def parse_raw_html(self, m: re.Match, state: BlockState) -> Optional[int]: + def parse_raw_html(self, m: Match, state: BlockState) -> Optional[int]: marker = m.group(0).strip() # rule 2 diff --git a/src/mistune/inline_parser.py b/src/mistune/inline_parser.py index 365a462..1fd961d 100644 --- a/src/mistune/inline_parser.py +++ b/src/mistune/inline_parser.py @@ -1,5 +1,5 @@ import re -from typing import Optional, List, Dict, Any +from typing import Optional, List, Dict, Any, Match from .core import Parser, InlineState from .util import ( escape, @@ -107,7 +107,7 @@ def __init__(self, hard_wrap: bool=False): name: getattr(self, 'parse_' + name) for name in self.rules } - def parse_escape(self, m: re.Match, state: InlineState) -> int: + def parse_escape(self, m: Match, state: InlineState) -> int: text = m.group(0) text = unescape_char(text) state.append_token({ @@ -116,7 +116,7 @@ def parse_escape(self, m: re.Match, state: InlineState) -> int: }) return m.end() - def parse_link(self, m: re.Match, state: InlineState) -> Optional[int]: + def parse_link(self, m: Match, state: InlineState) -> Optional[int]: pos = m.end() marker = m.group(0) @@ -200,7 +200,7 @@ def __parse_link_token(self, is_image, text, attrs, state): } return token - def parse_auto_link(self, m: re.Match, state: InlineState) -> int: + def parse_auto_link(self, m: Match, state: InlineState) -> int: text = m.group(0) pos = m.end() if state.in_link: @@ -211,7 +211,7 @@ def parse_auto_link(self, m: re.Match, state: InlineState) -> int: self._add_auto_link(text, text, state) return pos - def parse_auto_email(self, m: re.Match, state: InlineState) -> int: + def parse_auto_email(self, m: Match, state: InlineState) -> int: text = m.group(0) pos = m.end() if state.in_link: @@ -230,7 +230,7 @@ def _add_auto_link(self, url, text, state): 'attrs': {'url': escape_url(url)}, }) - def parse_emphasis(self, m: re.Match, state: InlineState) -> int: + def parse_emphasis(self, m: Match, state: InlineState) -> int: pos = m.end() marker = m.group(0) @@ -279,7 +279,7 @@ def parse_emphasis(self, m: re.Match, state: InlineState) -> int: }) return end_pos - def parse_codespan(self, m: re.Match, state: InlineState) -> int: + def parse_codespan(self, m: Match, state: InlineState) -> int: marker = m.group(0) # require same marker with same length at end @@ -301,15 +301,15 @@ def parse_codespan(self, m: re.Match, state: InlineState) -> int: state.append_token({'type': 'text', 'raw': marker}) return pos - def parse_linebreak(self, m: re.Match, state: InlineState) -> int: + def parse_linebreak(self, m: Match, state: InlineState) -> int: state.append_token({'type': 'linebreak'}) return m.end() - def parse_softbreak(self, m: re.Match, state: InlineState) -> int: + def parse_softbreak(self, m: Match, state: InlineState) -> int: state.append_token({'type': 'softbreak'}) return m.end() - def parse_inline_html(self, m: re.Match, state: InlineState) -> int: + def parse_inline_html(self, m: Match, state: InlineState) -> int: end_pos = m.end() html = m.group(0) state.append_token({'type': 'inline_html', 'raw': html}) @@ -351,7 +351,7 @@ def parse(self, state: InlineState) -> List[Dict[str, Any]]: self.process_text(state.src[pos:], state) return state.tokens - def precedence_scan(self, m: re.Match, state: InlineState, end_pos: int, rules=None): + def precedence_scan(self, m: Match, state: InlineState, end_pos: int, rules=None): if rules is None: rules = ['codespan', 'link', 'prec_auto_link', 'prec_inline_html']