(state: StateBlock, startLine: int, _endLine: int, silent: bool)
| 7 | |
| 8 | |
| 9 | def reference(state: StateBlock, startLine: int, _endLine: int, silent: bool) -> bool: |
| 10 | LOGGER.debug( |
| 11 | "entering reference: %s, %s, %s, %s", state, startLine, _endLine, silent |
| 12 | ) |
| 13 | |
| 14 | pos = state.bMarks[startLine] + state.tShift[startLine] |
| 15 | maximum = state.eMarks[startLine] |
| 16 | nextLine = startLine + 1 |
| 17 | |
| 18 | if state.is_code_block(startLine): |
| 19 | return False |
| 20 | |
| 21 | if state.src[pos] != "[": |
| 22 | return False |
| 23 | |
| 24 | string = state.src[pos : maximum + 1] |
| 25 | |
| 26 | # string = state.getLines(startLine, nextLine, state.blkIndent, False).strip() |
| 27 | maximum = len(string) |
| 28 | |
| 29 | labelEnd = None |
| 30 | pos = 1 |
| 31 | while pos < maximum: |
| 32 | ch = charCodeAt(string, pos) |
| 33 | if ch == 0x5B: # /* [ */ |
| 34 | return False |
| 35 | elif ch == 0x5D: # /* ] */ |
| 36 | labelEnd = pos |
| 37 | break |
| 38 | elif ch == 0x0A: # /* \n */ |
| 39 | if (lineContent := getNextLine(state, nextLine)) is not None: |
| 40 | string += lineContent |
| 41 | maximum = len(string) |
| 42 | nextLine += 1 |
| 43 | elif ch == 0x5C: # /* \ */ |
| 44 | pos += 1 |
| 45 | if ( |
| 46 | pos < maximum |
| 47 | and charCodeAt(string, pos) == 0x0A |
| 48 | and (lineContent := getNextLine(state, nextLine)) is not None |
| 49 | ): |
| 50 | string += lineContent |
| 51 | maximum = len(string) |
| 52 | nextLine += 1 |
| 53 | pos += 1 |
| 54 | |
| 55 | if ( |
| 56 | labelEnd is None or labelEnd < 0 or charCodeAt(string, labelEnd + 1) != 0x3A |
| 57 | ): # /* : */ |
| 58 | return False |
| 59 | |
| 60 | # [label]: destination 'title' |
| 61 | # ^^^ skip optional whitespace here |
| 62 | pos = labelEnd + 2 |
| 63 | while pos < maximum: |
| 64 | ch = charCodeAt(string, pos) |
| 65 | if ch == 0x0A: |
| 66 | if (lineContent := getNextLine(state, nextLine)) is not None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…