diff --git a/.github/workflows/check-code-snippets.yaml b/.github/workflows/check-code-snippets.yaml index 714e6a7d..476f6eb0 100644 --- a/.github/workflows/check-code-snippets.yaml +++ b/.github/workflows/check-code-snippets.yaml @@ -29,4 +29,4 @@ jobs: pip install requests - name: Validate code snippets run: | - python ./scripts/check-code-snippets.py . + python ./scripts/check_code_snippets.py . diff --git a/scripts/check-code-snippets.py b/scripts/check-code-snippets.py deleted file mode 100644 index 12c705c4..00000000 --- a/scripts/check-code-snippets.py +++ /dev/null @@ -1,73 +0,0 @@ -import os -import re -import sys -from typing import Optional, Tuple - -import requests - -def split_url_and_range(url: str) -> Tuple[str, Optional[int], Optional[int]]: - base, frag = url.split("#", 1) - m = re.match(r'L(\d+)(?:-L?(\d+))?$', frag) - start = int(m.group(1)) - end = int(m.group(2)) if m.group(2) else None - return base, start, end - -def fetch_raw(source: str) -> str: - r = requests.get(source) - return r.text - -def main(): - in_code = False - code = '' - content = '' - start_line = 0 - end_line = 0 - md_files = [] - - for root, dirs, files in os.walk(sys.argv[1]): - for name in files: - if name.endswith('.md'): - md_files.append(os.path.join(root, name)) - else: - continue - - for md in md_files: - print("Checking code in the", md) - - with open(md, "r", encoding="utf-8") as f: - md = f.read() - - md_lines = md.splitlines() - for line in md_lines: - if in_code: - if re.search("^```[a-zA-Z].*", line): - continue - - if re.search("^```$", line): - in_code = False - continue - - code += line + '\n' - continue - - if line.startswith("