Skip to content

Add auto-generated MLIR documentation #2

@jungmair

Description

@jungmair

As described here, a github actions workflow should be created for this repository which:

  1. takes the workflow run id from the triggering workflow
  2. Waits until the dispatching workflow run is completed (have a look here)
  3. Downloads the artifacts
  4. Post-processes the markdown files in order to work for docusaurus (see script draft below)
  5. Check if there are any differences (e.g., using git).
  6. If yes: automatically create pull request

Draft for post-processing script:

import re
import sys

def convert_markdown_to_html(input_file, output_file):
    # Read the input file
    with open(input_file, 'r') as file:
        lines = file.readlines()

    in_markdown_block = False
    output_lines = []
    current_block = []

    # Iterate through each line in the input file
    for line in lines:
        # Check if we are entering a markdown block
        if "{{% markdown %}}" in line:
            in_markdown_block = True
            # Retain the line before the block and start processing inside the block
            output_lines.append(line.split("{{% markdown %}}")[0])  # Retain text before the marker
            current_block = []  # Reset the current block for processing
            continue

        # Check if we are leaving a markdown block
        if "{{% /markdown %}}" in line:
            in_markdown_block = False
            # Process the block and wrap it in <ul>
            output_lines.append("<ul>")  # Start the unordered list
            # Add processed markdown content (list items)
            for list_item in current_block:
                # Process each list item inside the markdown block
                match = re.match(r'([^\(]+)\s?\(`([^`]+)`\)', list_item.strip())
                if match:
                    attribute = match.group(1).strip()
                    mlir_type = match.group(2).strip()
                    html_item = f"<li><strong>{attribute}</strong>: Enum case: {attribute} ({mlir_type})</li>"
                    output_lines.append(html_item)
                else:
                    output_lines.append(f"<li>{list_item.strip()}</li>")
            output_lines.append("</ul>")  # Close the unordered list
            output_lines.append(line.split("{{% /markdown %}}")[1])  # Retain text after the marker
            continue

        # Process lines inside the markdown block (for list items)
        if in_markdown_block:
            if line.strip().startswith("* "):  # Markdown list item
                current_block.append(line.strip()[2:])  # Remove "* " from the start
            else:
                current_block.append(line)  # Add non-list content to the current block
        else:
            output_lines.append(line)

    # Write the output to the output file
    with open(output_file, 'w') as file:
        file.writelines(output_lines)

    print(f"HTML output written to {output_file}")

# Command-line usage
if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python convert_markdown_to_html.py input_file output_file")
        sys.exit(1)

    input_file = sys.argv[1]
    output_file = sys.argv[2]
    convert_markdown_to_html(input_file, output_file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions