|
|
|
@ -1,5 +1,5 @@ |
|
|
|
import re |
|
|
|
from typing import TypedDict |
|
|
|
from typing import TypedDict, Union |
|
|
|
|
|
|
|
CODE_INCLUDE_RE = re.compile(r"^\{\*\s*(\S+)\s*(.*)\*\}$") |
|
|
|
CODE_INCLUDE_PLACEHOLDER = "<CODE_INCLUDE>" |
|
|
|
@ -50,8 +50,8 @@ class MarkdownLinkInfo(TypedDict): |
|
|
|
line_no: int |
|
|
|
url: str |
|
|
|
text: str |
|
|
|
title: str | None |
|
|
|
attributes: str | None |
|
|
|
title: Union[str, None] |
|
|
|
attributes: Union[str, None] |
|
|
|
full_match: str |
|
|
|
|
|
|
|
|
|
|
|
@ -285,7 +285,11 @@ def _add_lang_code_to_url(url: str, lang_code: str) -> str: |
|
|
|
|
|
|
|
|
|
|
|
def _construct_markdown_link( |
|
|
|
url: str, text: str, title: str | None, attributes: str | None, lang_code: str |
|
|
|
url: str, |
|
|
|
text: str, |
|
|
|
title: Union[str, None], |
|
|
|
attributes: Union[str, None], |
|
|
|
lang_code: str, |
|
|
|
) -> str: |
|
|
|
""" |
|
|
|
Construct a markdown link, adjusting the URL for the given language code if needed. |
|
|
|
@ -545,7 +549,7 @@ def extract_multiline_code_blocks(text: list[str]) -> list[MultilineCodeBlockInf |
|
|
|
return blocks |
|
|
|
|
|
|
|
|
|
|
|
def _split_hash_comment(line: str) -> tuple[str, str | None]: |
|
|
|
def _split_hash_comment(line: str) -> tuple[str, Union[str, None]]: |
|
|
|
match = HASH_COMMENT_RE.match(line) |
|
|
|
if match: |
|
|
|
code = match.group("code").rstrip() |
|
|
|
@ -554,7 +558,7 @@ def _split_hash_comment(line: str) -> tuple[str, str | None]: |
|
|
|
return line.rstrip(), None |
|
|
|
|
|
|
|
|
|
|
|
def _split_slashes_comment(line: str) -> tuple[str, str | None]: |
|
|
|
def _split_slashes_comment(line: str) -> tuple[str, Union[str, None]]: |
|
|
|
match = SLASHES_COMMENT_RE.match(line) |
|
|
|
if match: |
|
|
|
code = match.group("code").rstrip() |
|
|
|
@ -600,8 +604,8 @@ def replace_multiline_code_block( |
|
|
|
|
|
|
|
code_block: list[str] = [] |
|
|
|
for line_a, line_b in zip(block_a["content"], block_b["content"]): |
|
|
|
line_a_comment: str | None = None |
|
|
|
line_b_comment: str | None = None |
|
|
|
line_a_comment: Union[str, None] = None |
|
|
|
line_b_comment: Union[str, None] = None |
|
|
|
|
|
|
|
# Handle comments based on language |
|
|
|
if block_language in { |
|
|
|
|