(state: StateInline, delimiters: list[Delimiter])
| 38 | |
| 39 | |
| 40 | def _postProcess(state: StateInline, delimiters: list[Delimiter]) -> None: |
| 41 | i = len(delimiters) - 1 |
| 42 | while i >= 0: |
| 43 | startDelim = delimiters[i] |
| 44 | |
| 45 | # /* _ */ /* * */ |
| 46 | if startDelim.marker != 0x5F and startDelim.marker != 0x2A: |
| 47 | i -= 1 |
| 48 | continue |
| 49 | |
| 50 | # Process only opening markers |
| 51 | if startDelim.end == -1: |
| 52 | i -= 1 |
| 53 | continue |
| 54 | |
| 55 | endDelim = delimiters[startDelim.end] |
| 56 | |
| 57 | # If the previous delimiter has the same marker and is adjacent to this one, |
| 58 | # merge those into one strong delimiter. |
| 59 | # |
| 60 | # `<em><em>whatever</em></em>` -> `<strong>whatever</strong>` |
| 61 | # |
| 62 | isStrong = ( |
| 63 | i > 0 |
| 64 | and delimiters[i - 1].end == startDelim.end + 1 |
| 65 | # check that first two markers match and adjacent |
| 66 | and delimiters[i - 1].marker == startDelim.marker |
| 67 | and delimiters[i - 1].token == startDelim.token - 1 |
| 68 | # check that last two markers are adjacent (we can safely assume they match) |
| 69 | and delimiters[startDelim.end + 1].token == endDelim.token + 1 |
| 70 | ) |
| 71 | |
| 72 | ch = chr(startDelim.marker) |
| 73 | |
| 74 | token = state.tokens[startDelim.token] |
| 75 | token.type = "strong_open" if isStrong else "em_open" |
| 76 | token.tag = "strong" if isStrong else "em" |
| 77 | token.nesting = 1 |
| 78 | token.markup = ch + ch if isStrong else ch |
| 79 | token.content = "" |
| 80 | |
| 81 | token = state.tokens[endDelim.token] |
| 82 | token.type = "strong_close" if isStrong else "em_close" |
| 83 | token.tag = "strong" if isStrong else "em" |
| 84 | token.nesting = -1 |
| 85 | token.markup = ch + ch if isStrong else ch |
| 86 | token.content = "" |
| 87 | |
| 88 | if isStrong: |
| 89 | state.tokens[delimiters[i - 1].token].content = "" |
| 90 | state.tokens[delimiters[startDelim.end + 1].token].content = "" |
| 91 | i -= 1 |
| 92 | |
| 93 | i -= 1 |
| 94 | |
| 95 | |
| 96 | def postProcess(state: StateInline) -> None: |
no outgoing calls
no test coverage detected
searching dependent graphs…