From 1e01524bbfb55ee0e6e30620916150e07d60e807 Mon Sep 17 00:00:00 2001 From: ClemensLinnhoff Date: Thu, 5 Sep 2024 18:49:21 +0200 Subject: [PATCH 1/2] Cleanup headlines Signed-off-by: ClemensLinnhoff --- content/geometry/Performance.adoc | 2 +- scripts/json2asciidoc.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/content/geometry/Performance.adoc b/content/geometry/Performance.adoc index 88f45941..3bb6d747 100644 --- a/content/geometry/Performance.adoc +++ b/content/geometry/Performance.adoc @@ -1,3 +1,3 @@ -= ASAM OpenMATERIAL Performance += Performance * ... \ No newline at end of file diff --git a/scripts/json2asciidoc.py b/scripts/json2asciidoc.py index bc3c3ea6..ff8d03c0 100644 --- a/scripts/json2asciidoc.py +++ b/scripts/json2asciidoc.py @@ -3,7 +3,7 @@ # Function to generate AsciiDoc content for each property def generate_asciidoc(field_name, schema, required_fields): - asciidoc_content = f"= {field_name.capitalize()} Documentation\n\n" + asciidoc_content = f"= {field_name.capitalize()}\n\n" field_data = schema['properties'][field_name] asciidoc_content += field_data.get("description", "") + "\n\n" From c48c4f12058a405b11d40996f3cac6dfd959c88e Mon Sep 17 00:00:00 2001 From: ClemensLinnhoff Date: Thu, 5 Sep 2024 19:03:53 +0200 Subject: [PATCH 2/2] Refactoring and documentation Signed-off-by: ClemensLinnhoff --- scripts/json2asciidoc.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/scripts/json2asciidoc.py b/scripts/json2asciidoc.py index ff8d03c0..1a14c031 100644 --- a/scripts/json2asciidoc.py +++ b/scripts/json2asciidoc.py @@ -1,8 +1,34 @@ import json import argparse -# Function to generate AsciiDoc content for each property + +def escape_special_chars(pattern): + """ + Escape special characters in the pattern string for AsciiDoc compatibility. + + Args: + pattern (str): The pattern string to be escaped. + + Returns: + str: The escaped pattern string. + """ + pattern = pattern.replace("\\", "\\\\") # Escape backslashes + pattern = pattern.replace("{", "\\{").replace("}", "\\}") # Escape curly braces + return pattern + + def generate_asciidoc(field_name, schema, required_fields): + """ + Generate AsciiDoc content for the specified field based on the JSON schema. + + Args: + field_name (str): The name of the field to generate documentation for. + schema (dict): The JSON schema dictionary. + required_fields (list): List of required fields for the specified field. + + Returns: + str: The generated AsciiDoc content. + """ asciidoc_content = f"= {field_name.capitalize()}\n\n" field_data = schema['properties'][field_name] asciidoc_content += field_data.get("description", "") + "\n\n" @@ -11,9 +37,10 @@ def generate_asciidoc(field_name, schema, required_fields): asciidoc_content += f"== {prop_name}\n" asciidoc_content += f"{prop_data.get('description', 'No description')}\n" - # Add a new line before pattern + # Add pattern inline and handle escaping of backslashes and curly braces if "pattern" in prop_data: - asciidoc_content += f"\n*Pattern:* `{prop_data['pattern']}`\n" + pattern = escape_special_chars(prop_data['pattern']) + asciidoc_content += f"\n*Pattern:* `{pattern}`\n" # Add a new line before required status if prop_name in required_fields: @@ -25,7 +52,11 @@ def generate_asciidoc(field_name, schema, required_fields): return asciidoc_content + def main(): + """ + Main function to handle command-line arguments, process the JSON schema, and generate the AsciiDoc documentation. + """ # Set up argument parser parser = argparse.ArgumentParser(description="Generate AsciiDoc documentation for a given JSON schema field.") parser.add_argument('json_schema_path', type=str, help="Path to the JSON schema file.") @@ -58,6 +89,6 @@ def main(): print(f"AsciiDoc generated successfully! Output saved to {output_filename}") + if __name__ == "__main__": main() -