diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml index 542ce49c0..eb4282c71 100644 --- a/.github/workflows/formatting.yml +++ b/.github/workflows/formatting.yml @@ -19,12 +19,13 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.12" - - name: Install CFEngine CLI + - name: Install tools run: | - pipx install cfengine + pipx install cfengine black - name: Run formatting command to (hopefully not) make changes run: | cfengine dev docs-format + black . - name: Check output.log file for warnings run: | ! grep WARNING output.log diff --git a/generator/_scripts/cfdoc_images_path_resolver.py b/generator/_scripts/cfdoc_images_path_resolver.py index 7af389931..6f95dbf6d 100644 --- a/generator/_scripts/cfdoc_images_path_resolver.py +++ b/generator/_scripts/cfdoc_images_path_resolver.py @@ -1,44 +1,49 @@ import re import os + def run(config): - """ Fixes images paths - The markdown files other than _index.markdown need img tag src values adjusted if they are relative. - They need to reference the parent directory with ../ prefixed to the relative location of the image file. + """Fixes images paths + The markdown files other than _index.markdown need img tag src values adjusted if they are relative. + They need to reference the parent directory with ../ prefixed to the relative location of the image file. """ markdown_files = config["markdown_files"] - + for file in markdown_files: process(file) + def load_references(file_path): try: - with open(file_path, 'r', encoding='utf-8') as f: + with open(file_path, "r", encoding="utf-8") as f: return f.read() except FileNotFoundError: return "" + def process(file_path): """Process a markdown file to fix image paths""" try: - with open(file_path, 'r', encoding='utf-8') as f: + with open(file_path, "r", encoding="utf-8") as f: content = f.read() - + is_index_file = os.path.basename(file_path) == "_index.markdown" - + if is_index_file: # For _index.markdown files, leave image paths as is. As they are on the same level return - + # Pattern to match img src with relative paths that need fixing # skips ../, /, or http img_pattern = r']*?)src="(?!\.\.\/|\/|https?:\/\/)([^"]+?)"([^>]*?)>' - + # Replace with ../ added to the path - modified_content = re.sub(img_pattern, r'', content, flags=re.IGNORECASE); + modified_content = re.sub( + img_pattern, r'', content, flags=re.IGNORECASE + ) if modified_content != content: - with open(file_path, 'w', encoding='utf-8') as f: + with open(file_path, "w", encoding="utf-8") as f: f.write(modified_content) - + except Exception as e: print(f"Error processing {file_path}: {e}") diff --git a/generator/_scripts/cfdoc_metadata.py b/generator/_scripts/cfdoc_metadata.py index 57ec6bcd8..e67154081 100644 --- a/generator/_scripts/cfdoc_metadata.py +++ b/generator/_scripts/cfdoc_metadata.py @@ -23,6 +23,7 @@ import os import json + def run(config): config["syntax_path"] = config["project_directory"] + "/_generated/syntax_map.json" config["syntax_map"] = json.load(open(config["syntax_path"], "r")) @@ -31,6 +32,7 @@ def run(config): for file in markdown_files: processMetaData(file, config) + # parse meta data lines, remove existing header for later reconstruction def parseHeader(lines): header = {} diff --git a/generator/_scripts/cfdoc_patch_header_nav.py b/generator/_scripts/cfdoc_patch_header_nav.py index 7786a6cb6..5b2fd121d 100644 --- a/generator/_scripts/cfdoc_patch_header_nav.py +++ b/generator/_scripts/cfdoc_patch_header_nav.py @@ -54,7 +54,10 @@ def patch(current_branch): for branch in data["docs"]: print( '
  • %s
  • ' - % ("../../.." + branch["Link"], branch["Title"].replace("Version ", "")), + % ( + "../../.." + branch["Link"], + branch["Title"].replace("Version ", ""), + ), file=f, ) with open("_includes/lts_versions_list.html", "w") as f: diff --git a/generator/_scripts/cfdoc_references_resolver.py b/generator/_scripts/cfdoc_references_resolver.py index 6e7d4816d..434f6c06c 100644 --- a/generator/_scripts/cfdoc_references_resolver.py +++ b/generator/_scripts/cfdoc_references_resolver.py @@ -2,81 +2,95 @@ import os import sys + def load_references(references_file): """Parse the _references.md file and return a dictionary of references.""" references = {} content = "" - + refs_path = os.path.join(os.environ.get("WRKDIR"), references_file) try: if os.path.exists(refs_path): - with open(refs_path, 'r', encoding='utf-8') as file: + with open(refs_path, "r", encoding="utf-8") as file: content = file.read() else: - sys.stderr.write(f"Warning: References file {refs_path} not found. No references will be added.") + sys.stderr.write( + f"Warning: References file {refs_path} not found. No references will be added." + ) return "" except Exception as e: sys.stderr.write(f"Error reading references file {refs_path}: {str(e)}") return "" - + # Pattern to match reference definitions: [ref]: url "title" pattern = r'\[(.*?)\]:\s+(.*?)(?:\s+"(.*?)")?\s*$' - + for match in re.finditer(pattern, content, re.MULTILINE): ref, url, title = match.groups() if title is None: title = "" references[ref] = (url, title) - + return references + def process(file_path, references): """Process a markdown file and replace reference links with direct links.""" - - with open(file_path, 'r', encoding='utf-8') as f: + + with open(file_path, "r", encoding="utf-8") as f: content = f.read() - + # Pattern to match reference links: [`text`][reference] - pattern = r'\[(.*?)\]\[(.*?)\]' + pattern = r"\[(.*?)\]\[(.*?)\]" + def replace_link(match): text, ref = match.groups() - ref = ref or text # if ref is empty use text as ref to support cases like [ref][] - + ref = ( + ref or text + ) # if ref is empty use text as ref to support cases like [ref][] + if ref in references: url, title = references[ref] if title: return f'[{text}]({url} "{title}")' else: - return f'[{text}]({url})' + return f"[{text}]({url})" else: - sys.stderr.write(f"References {ref} is not found in the _references.md. File: {file_path}") + sys.stderr.write( + f"References {ref} is not found in the _references.md. File: {file_path}" + ) return match.group(0) - + new_content = re.sub(pattern, replace_link, content) - + # finds functions except ones already processed inside [] - functions_pattern = r'(?