mypastebin/generate_css.py
2025-05-29 22:40:58 +02:00

26 lines
752 B
Python

import os
from pygments.styles import get_all_styles
from pygments.formatters import HtmlFormatter
# Define la carpeta de destino para los archivos CSS
OUTPUT_DIR = os.path.join('static', 'css')
# Crea la carpeta si no existe
os.makedirs(OUTPUT_DIR, exist_ok=True)
# Itera sobre todos los estilos disponibles en Pygments
for style in get_all_styles():
formatter = HtmlFormatter(style=style, linenos=True, cssclass="highlight")
css = formatter.get_style_defs('.highlight')
# Define el nombre del archivo CSS
css_filename = f"{style}.css"
css_path = os.path.join(OUTPUT_DIR, css_filename)
# Escribe el CSS en el archivo
with open(css_path, 'w') as f:
f.write(css)
print(f"Generado: {css_path}")