mirror of
https://github.com/pi-hole/FTL.git
synced 2025-12-24 19:35:29 +00:00
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 <github@rdwebdesign.com.br>
This commit is contained in:
committed by
Adam Warner
parent
31102139ec
commit
c076b1bb39
@@ -64,7 +64,7 @@ sudo pihole-FTL --config dns.dnssec=true
|
|||||||
section_stack = [stripped.strip("[]")]
|
section_stack = [stripped.strip("[]")]
|
||||||
documentation.append(f"\n## `[{'.'.join(section_stack)}]`\n")
|
documentation.append(f"\n## `[{'.'.join(section_stack)}]`\n")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# If we are in a config section, start buffering comments
|
# If we are in a config section, start buffering comments
|
||||||
elif stripped.startswith("#"):
|
elif stripped.startswith("#"):
|
||||||
if in_config:
|
if in_config:
|
||||||
@@ -86,7 +86,7 @@ sudo pihole-FTL --config dns.dnssec=true
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
value = value_lines[0]
|
value = value_lines[0]
|
||||||
|
|
||||||
documentation.append(f"### `{key}`\n")
|
documentation.append(f"### `{key}`\n")
|
||||||
|
|
||||||
# Process the comments collected for this key
|
# Process the comments collected for this key
|
||||||
@@ -106,22 +106,22 @@ sudo pihole-FTL --config dns.dnssec=true
|
|||||||
|
|
||||||
# Bold "Allowed values are:"
|
# Bold "Allowed values are:"
|
||||||
line = re.sub(
|
line = re.sub(
|
||||||
r'(^|\s)(Allowed values are:)',
|
r'(^|\s)(Allowed values are:)',
|
||||||
r'\1**Allowed values are:**',
|
r'\1**Allowed values are:**',
|
||||||
line
|
line
|
||||||
)
|
)
|
||||||
|
|
||||||
# Bold "Example:"
|
# Bold "Example:"
|
||||||
line = re.sub(
|
line = re.sub(
|
||||||
r'(^|\s)(Example:)',
|
r'(^|\s)(Example:)',
|
||||||
r'\1**Example:**',
|
r'\1**Example:**',
|
||||||
line
|
line
|
||||||
)
|
)
|
||||||
|
|
||||||
# Insert blank line before bullet if needed
|
# Insert blank line before bullet if needed
|
||||||
if is_bullet and not prev_is_bullet and not prev_is_blank:
|
if is_bullet and not prev_is_bullet and not prev_is_blank:
|
||||||
adjusted_comments.append("")
|
adjusted_comments.append("")
|
||||||
|
|
||||||
# Default: just append the line
|
# Default: just append the line
|
||||||
adjusted_comments.append(line)
|
adjusted_comments.append(line)
|
||||||
i += 1
|
i += 1
|
||||||
@@ -133,7 +133,7 @@ sudo pihole-FTL --config dns.dnssec=true
|
|||||||
documentation.append("**Default value:**")
|
documentation.append("**Default value:**")
|
||||||
documentation.append("")
|
documentation.append("")
|
||||||
documentation.append("```toml")
|
documentation.append("```toml")
|
||||||
documentation.append(f"{value}")
|
documentation.append(f" {value}")
|
||||||
documentation.append("```")
|
documentation.append("```")
|
||||||
documentation.append("")
|
documentation.append("")
|
||||||
else:
|
else:
|
||||||
@@ -149,7 +149,7 @@ sudo pihole-FTL --config dns.dnssec=true
|
|||||||
documentation.append(f" [{'.'.join(section_stack)}]")
|
documentation.append(f" [{'.'.join(section_stack)}]")
|
||||||
# Indent multi-line values for TOML block
|
# Indent multi-line values for TOML block
|
||||||
if "\n" in value:
|
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}")
|
documentation.append(f" {key} = {indented_value}")
|
||||||
else:
|
else:
|
||||||
documentation.append(f" {key} = {value}")
|
documentation.append(f" {key} = {value}")
|
||||||
@@ -161,7 +161,7 @@ sudo pihole-FTL --config dns.dnssec=true
|
|||||||
if "\n" in value and value.strip().startswith("["):
|
if "\n" in value and value.strip().startswith("["):
|
||||||
# Flatten multi-line array to single line for CLI
|
# Flatten multi-line array to single line for CLI
|
||||||
array_str = "".join(value.split())
|
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:
|
else:
|
||||||
documentation.append(f" sudo pihole-FTL --config {full_key}={value}")
|
documentation.append(f" sudo pihole-FTL --config {full_key}={value}")
|
||||||
documentation.append(" ```")
|
documentation.append(" ```")
|
||||||
@@ -172,7 +172,7 @@ sudo pihole-FTL --config dns.dnssec=true
|
|||||||
documentation.append(" environment:")
|
documentation.append(" environment:")
|
||||||
yaml_value = value.replace('"',"'")
|
yaml_value = value.replace('"',"'")
|
||||||
if "\n" in yaml_value:
|
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(f" {env_var}: {yaml_value}")
|
||||||
documentation.append(" ```\n")
|
documentation.append(" ```\n")
|
||||||
comment_buffer = []
|
comment_buffer = []
|
||||||
@@ -185,15 +185,15 @@ def wrap_examples_and_allowed_values(line):
|
|||||||
- Complete arrays: [ "example" ] -> `[ "example" ]`
|
- Complete arrays: [ "example" ] -> `[ "example" ]`
|
||||||
- Quoted strings: "example" -> `"example"`
|
- Quoted strings: "example" -> `"example"`
|
||||||
- Angle brackets: <example> -> `<example>`
|
- Angle brackets: <example> -> `<example>`
|
||||||
|
|
||||||
Ensures no nested backticks appear within wrapped content.
|
Ensures no nested backticks appear within wrapped content.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Process other patterns
|
# Process other patterns
|
||||||
result = ''
|
result = ''
|
||||||
i = 0
|
i = 0
|
||||||
in_backticks = False
|
in_backticks = False
|
||||||
|
|
||||||
while i < len(line):
|
while i < len(line):
|
||||||
# Skip content already in backticks
|
# Skip content already in backticks
|
||||||
if in_backticks:
|
if in_backticks:
|
||||||
@@ -202,7 +202,7 @@ def wrap_examples_and_allowed_values(line):
|
|||||||
result += line[i]
|
result += line[i]
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Look for patterns to wrap
|
# Look for patterns to wrap
|
||||||
if line[i:i+1] == '"':
|
if line[i:i+1] == '"':
|
||||||
# Find the matching closing quote
|
# Find the matching closing quote
|
||||||
@@ -238,23 +238,23 @@ def wrap_examples_and_allowed_values(line):
|
|||||||
bracket_count += 1
|
bracket_count += 1
|
||||||
elif line[j] == ']':
|
elif line[j] == ']':
|
||||||
bracket_count -= 1
|
bracket_count -= 1
|
||||||
if bracket_count == 0:
|
if bracket_count == 0:
|
||||||
break
|
break
|
||||||
j += 1
|
j += 1
|
||||||
if bracket_count == 0 and j < len(line): # Found matching closing bracket
|
if bracket_count == 0 and j < len(line): # Found matching closing bracket
|
||||||
square_content = line[i:j+1]
|
square_content = line[i:j+1]
|
||||||
result += f'`{square_content}`'
|
result += f'`{square_content}`'
|
||||||
i = j + 1
|
i = j + 1
|
||||||
in_backticks = False
|
in_backticks = False
|
||||||
|
|
||||||
else: # No matching closing bracket found
|
else: # No matching closing bracket found
|
||||||
result += line[i]
|
result += line[i]
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
result += line[i]
|
result += line[i]
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def write_markdown_doc(input_toml_path, output_md_path):
|
def write_markdown_doc(input_toml_path, output_md_path):
|
||||||
@@ -282,4 +282,3 @@ if __name__ == "__main__":
|
|||||||
output_path = sys.argv[2]
|
output_path = sys.argv[2]
|
||||||
write_markdown_doc(input_path, output_path)
|
write_markdown_doc(input_path, output_path)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user