import os from jinja2 import Environment, Template import markdown # Configuration materials = ['1_situation', '2_binding', '3_paperformat', '4_add_ons'] output_file = 'output.html' # Prepare data for template rendering data = [] for folder in materials: markdown_files = os.listdir(folder) folder_data = { 'folder_name': folder, 'markdown_files': [] } for markdown_file in markdown_files: file_path = os.path.join(folder, markdown_file) with open(file_path, 'r') as file: content = file.read() folder_data['markdown_files'].append({'file_name': markdown_file, 'content': content}) data.append(folder_data) # Define the HTML template template = """ Markdown Folders
{% for folder_data in data %}

{{ folder_data.folder_name }}

    {% for file_data in folder_data.markdown_files %}
  • {{ file_data.file_name }}

    {{ file_data.content }}
  • {% endfor %}
{% endfor %}
""" # Create the Jinja2 environment env = Environment() # Create the template from the template string template = env.from_string(template) # Render the template with data html_output = template.render(data=data) # Write the HTML output to file with open(output_file, 'w') as file: file.write(html_output)