Skip to content

Commit a27240a

Browse files
Skipped references resolving inside code blocks
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
1 parent b47a05c commit a27240a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

generator/_scripts/cfdoc_references_resolver.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,24 @@ def process(file_path, references):
4141
with open(file_path, "r", encoding="utf-8") as f:
4242
content = f.read()
4343

44+
# find code blocks positions to skip them
45+
code_ranges = []
46+
for match in re.finditer(r'```[\s\S]*?```', content):
47+
code_ranges.append((match.start(), match.end()))
48+
49+
def is_in_code_block(pos):
50+
for start, end in code_ranges:
51+
if start <= pos < end:
52+
return True
53+
return False
54+
4455
# Pattern to match reference links: [`text`][reference]
4556
pattern = r"\[(.*?)\]\[(.*?)\]"
4657

4758
def replace_link(match):
59+
if is_in_code_block(match.start()):
60+
return match.group(0)
61+
4862
text, ref = match.groups()
4963
ref = (
5064
ref or text
@@ -69,6 +83,9 @@ def replace_link(match):
6983
functions_pattern = r"(?<!\[)\`([^\s]*?)\(\)\`(?!\])"
7084

7185
def replace_function_link(match):
86+
if is_in_code_block(match.start()):
87+
return match.group(0)
88+
7289
ref = match.group(1)
7390
text = f"{ref}()"
7491
ref_lower = ref.lower()

0 commit comments

Comments
 (0)