Return a ` ` element containing the escaped matching text.
| 434 | |
| 435 | |
| 436 | class BacktickInlineProcessor(InlineProcessor): |
| 437 | """ Return a `<code>` element containing the escaped matching text. """ |
| 438 | |
| 439 | def __init__(self, pattern: str): |
| 440 | InlineProcessor.__init__(self, pattern) |
| 441 | self.ESCAPED_BSLASH = '{}{}{}'.format(util.STX, ord('\\'), util.ETX) |
| 442 | self.tag = 'code' |
| 443 | """ The tag of the rendered element. """ |
| 444 | |
| 445 | def find_code_spans(self, start: int, text: str) -> tuple[int, int] | None: |
| 446 | """Find code spans.""" |
| 447 | |
| 448 | last = len(text) |
| 449 | |
| 450 | # Get the maximum starting ticks |
| 451 | max_ticks = 0 |
| 452 | while start < last and text[start] == '`': |
| 453 | max_ticks += 1 |
| 454 | start += 1 |
| 455 | |
| 456 | if not max_ticks: # pragma: no cover |
| 457 | # This is not ever expected to happen. |
| 458 | return None |
| 459 | |
| 460 | longest_span = 0 |
| 461 | end = 0 |
| 462 | |
| 463 | # Find an ending span of backticks that matches our opening |
| 464 | i = start |
| 465 | while i < last: |
| 466 | span_length = 0 |
| 467 | while i < last and text[i] == '`': |
| 468 | span_length += 1 |
| 469 | i += 1 |
| 470 | if not span_length: |
| 471 | i += 1 |
| 472 | continue |
| 473 | |
| 474 | # Did we find the end? |
| 475 | if max_ticks == span_length: |
| 476 | return start, i - span_length |
| 477 | |
| 478 | # Track the longest span of backticks we find as a fallback. |
| 479 | if span_length > longest_span: |
| 480 | longest_span = span_length |
| 481 | end = i |
| 482 | |
| 483 | # Since we didn't find an exact matching start and end, |
| 484 | # adjust start to match the largest end we could calculate. |
| 485 | if longest_span: |
| 486 | return start - (max_ticks - longest_span), end - longest_span |
| 487 | |
| 488 | # We could not find a suitable pairing |
| 489 | return None |
| 490 | |
| 491 | def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element | str | None, int | None, int | None]: |
| 492 | """ |
| 493 | If the match contains `group(3)` of a pattern, then return a `code` |
no outgoing calls
no test coverage detected