From c076b1bb394054e243dac4df234e4d5feb1c2d74 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 7 Jul 2025 18:43:38 -0300 Subject: [PATCH] Fix indentation for multiline values - multiline "default values" section: add 2 spaces on the first line - use `.strip()` to remove unneeded initial spaces from TOML example tab - adjust the indentation size for TOML and YAML example tabs - remove trailing spaces Signed-off-by: RD WebDesign --- tools/pihole_toml_to_markdown.py | 43 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/tools/pihole_toml_to_markdown.py b/tools/pihole_toml_to_markdown.py index f4a50d33..a26d4c41 100644 --- a/tools/pihole_toml_to_markdown.py +++ b/tools/pihole_toml_to_markdown.py @@ -64,7 +64,7 @@ sudo pihole-FTL --config dns.dnssec=true section_stack = [stripped.strip("[]")] documentation.append(f"\n## `[{'.'.join(section_stack)}]`\n") continue - + # If we are in a config section, start buffering comments elif stripped.startswith("#"): if in_config: @@ -86,7 +86,7 @@ sudo pihole-FTL --config dns.dnssec=true else: value = value_lines[0] - + documentation.append(f"### `{key}`\n") # Process the comments collected for this key @@ -106,22 +106,22 @@ sudo pihole-FTL --config dns.dnssec=true # Bold "Allowed values are:" line = re.sub( - r'(^|\s)(Allowed values are:)', - r'\1**Allowed values are:**', + r'(^|\s)(Allowed values are:)', + r'\1**Allowed values are:**', line ) # Bold "Example:" line = re.sub( - r'(^|\s)(Example:)', - r'\1**Example:**', + r'(^|\s)(Example:)', + r'\1**Example:**', line - ) + ) # Insert blank line before bullet if needed if is_bullet and not prev_is_bullet and not prev_is_blank: adjusted_comments.append("") - + # Default: just append the line adjusted_comments.append(line) i += 1 @@ -133,7 +133,7 @@ sudo pihole-FTL --config dns.dnssec=true documentation.append("**Default value:**") documentation.append("") documentation.append("```toml") - documentation.append(f"{value}") + documentation.append(f" {value}") documentation.append("```") documentation.append("") else: @@ -149,7 +149,7 @@ sudo pihole-FTL --config dns.dnssec=true documentation.append(f" [{'.'.join(section_stack)}]") # Indent multi-line values for TOML block if "\n" in value: - indented_value = "\n".join(" " + v for v in value.splitlines()) + indented_value = "\n".join(" " + v for v in value.splitlines()).strip() documentation.append(f" {key} = {indented_value}") else: documentation.append(f" {key} = {value}") @@ -161,7 +161,7 @@ sudo pihole-FTL --config dns.dnssec=true if "\n" in value and value.strip().startswith("["): # Flatten multi-line array to single line for CLI array_str = "".join(value.split()) - documentation.append(f" sudo pihole-FTL --config {full_key}='{array_str}'") + documentation.append(f" sudo pihole-FTL --config {full_key}='{array_str}'") else: documentation.append(f" sudo pihole-FTL --config {full_key}={value}") documentation.append(" ```") @@ -172,7 +172,7 @@ sudo pihole-FTL --config dns.dnssec=true documentation.append(" environment:") yaml_value = value.replace('"',"'") if "\n" in yaml_value: - yaml_value = f"|\n " + "\n ".join(yaml_value.splitlines()) + yaml_value = f"|\n " + "\n ".join(yaml_value.splitlines()) documentation.append(f" {env_var}: {yaml_value}") documentation.append(" ```\n") comment_buffer = [] @@ -185,15 +185,15 @@ def wrap_examples_and_allowed_values(line): - Complete arrays: [ "example" ] -> `[ "example" ]` - Quoted strings: "example" -> `"example"` - Angle brackets: -> `` - + Ensures no nested backticks appear within wrapped content. """ - + # Process other patterns result = '' i = 0 in_backticks = False - + while i < len(line): # Skip content already in backticks if in_backticks: @@ -202,7 +202,7 @@ def wrap_examples_and_allowed_values(line): result += line[i] i += 1 continue - + # Look for patterns to wrap if line[i:i+1] == '"': # Find the matching closing quote @@ -238,23 +238,23 @@ def wrap_examples_and_allowed_values(line): bracket_count += 1 elif line[j] == ']': bracket_count -= 1 - if bracket_count == 0: + if bracket_count == 0: break - j += 1 + j += 1 if bracket_count == 0 and j < len(line): # Found matching closing bracket square_content = line[i:j+1] result += f'`{square_content}`' i = j + 1 in_backticks = False - + else: # No matching closing bracket found result += line[i] i += 1 - + else: result += line[i] i += 1 - + return result def write_markdown_doc(input_toml_path, output_md_path): @@ -282,4 +282,3 @@ if __name__ == "__main__": output_path = sys.argv[2] write_markdown_doc(input_path, output_path) -