MCPcopy Create free account
hub / github.com/0xAX/linux-insides / __handle_md__

Function __handle_md__

scripts/check_code_snippets.py:25–61  ·  view source on GitHub ↗
(md: str, path: str)

Source from the content-addressed store, hash-verified

23 return r.text
24
25def __handle_md__(md: str, path: str):
26 in_code = False
27 code = ''
28 content = ''
29
30 md_lines = md.splitlines()
31
32 for line in md_lines:
33 if in_code:
34 if re.search("^```[a-zA-Z].*", line):
35 continue
36
37 if re.search("^```$", line):
38 in_code = False
39 continue
40
41 code += line + '\n'
42 continue
43
44 if line.startswith("<!--"):
45 in_code = True
46 (uri, start, end) = __split_url_and_range__(line.split(' ')[1])
47 content = "\n".join(__fetch_raw__(uri).splitlines()[start-1:end]).rstrip()
48 continue
49
50 if code != '':
51 if code.rstrip() != content:
52 print("Error in", path)
53 print("Code in book:")
54 print(code)
55 print("Code from github:")
56 print(content)
57 sys.exit(1)
58
59 code = ''
60 content = ''
61 continue
62
63def __main__():
64 path = ''

Callers 1

__main__Function · 0.85

Calls 2

__split_url_and_range__Function · 0.85
__fetch_raw__Function · 0.85

Tested by

no test coverage detected