ParserBlock#ruler -> Ruler [[Ruler]] instance. Keep configuration of block rules.
| 46 | |
| 47 | |
| 48 | class ParserBlock: |
| 49 | """ |
| 50 | ParserBlock#ruler -> Ruler |
| 51 | |
| 52 | [[Ruler]] instance. Keep configuration of block rules. |
| 53 | """ |
| 54 | |
| 55 | def __init__(self) -> None: |
| 56 | self.ruler = Ruler[RuleFuncBlockType]() |
| 57 | for name, rule, alt in _rules: |
| 58 | self.ruler.push(name, rule, {"alt": alt}) |
| 59 | |
| 60 | def tokenize(self, state: StateBlock, startLine: int, endLine: int) -> None: |
| 61 | """Generate tokens for input range.""" |
| 62 | rules = self.ruler.getRules("") |
| 63 | line = startLine |
| 64 | maxNesting = state.md.options.maxNesting |
| 65 | hasEmptyLines = False |
| 66 | |
| 67 | while line < endLine: |
| 68 | state.line = line = state.skipEmptyLines(line) |
| 69 | if line >= endLine: |
| 70 | break |
| 71 | if state.sCount[line] < state.blkIndent: |
| 72 | # Termination condition for nested calls. |
| 73 | # Nested calls currently used for blockquotes & lists |
| 74 | break |
| 75 | if state.level >= maxNesting: |
| 76 | # If nesting level exceeded - skip tail to the end. |
| 77 | # That's not ordinary situation and we should not care about content. |
| 78 | state.line = endLine |
| 79 | break |
| 80 | |
| 81 | # Try all possible rules. |
| 82 | # On success, rule should: |
| 83 | # - update `state.line` |
| 84 | # - update `state.tokens` |
| 85 | # - return True |
| 86 | for rule in rules: |
| 87 | if rule(state, line, endLine, False): |
| 88 | break |
| 89 | |
| 90 | # set state.tight if we had an empty line before current tag |
| 91 | # i.e. latest empty line should not count |
| 92 | state.tight = not hasEmptyLines |
| 93 | |
| 94 | line = state.line |
| 95 | |
| 96 | # paragraph might "eat" one newline after it in nested lists |
| 97 | if (line - 1) < endLine and state.isEmpty(line - 1): |
| 98 | hasEmptyLines = True |
| 99 | |
| 100 | if line < endLine and state.isEmpty(line): |
| 101 | hasEmptyLines = True |
| 102 | line += 1 |
| 103 | state.line = line |
| 104 | |
| 105 | def parse( |
no outgoing calls
no test coverage detected
searching dependent graphs…