64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
from pygments.formatters import HtmlFormatter
|
|
import re
|
|
|
|
def get_class_definitions():
|
|
try:
|
|
formatter = HtmlFormatter()
|
|
style_defs = formatter.get_style_defs()
|
|
return style_defs
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
return ""
|
|
|
|
def parse_class_definitions(class_definitions):
|
|
class_colors = {}
|
|
class_weights = {}
|
|
|
|
color_pattern = r'\.(\w+) {[^}]*?color: (#[0-9A-Fa-f]+)[^}]*}(?: /\* (.*?) \*/)?'
|
|
weight_pattern = r'\.(\w+) {[^}]*?(font-(weight|style): \w+)[^}]*}(?: /\* (.*?) \*/)?'
|
|
|
|
color_matches = re.findall(color_pattern, class_definitions)
|
|
weight_matches = re.findall(weight_pattern, class_definitions)
|
|
|
|
for match in color_matches:
|
|
class_name, color, comment = match
|
|
comment = comment.strip() if comment else ""
|
|
class_colors[class_name] = (color, comment)
|
|
|
|
for match in weight_matches:
|
|
class_name, weight, _, comment = match
|
|
comment = comment.strip() if comment else ""
|
|
class_weights[class_name] = (weight, comment)
|
|
|
|
return class_colors, class_weights
|
|
|
|
def main():
|
|
class_definitions = get_class_definitions()
|
|
if class_definitions:
|
|
class_colors, class_weights = parse_class_definitions(class_definitions)
|
|
|
|
# Print class colors
|
|
print("# Define colors for different classes (modify as needed)")
|
|
print("class_colors = {")
|
|
for class_name, (color, comment) in class_colors.items():
|
|
if comment:
|
|
print(f' "{class_name}": "{color}", # {comment}')
|
|
else:
|
|
print(f' "{class_name}": "{color}",')
|
|
print("}")
|
|
|
|
# Print class weights
|
|
print("\n# Define weights for different classes (modify as needed)")
|
|
print("class_weights = {")
|
|
for class_name, (weight, comment) in class_weights.items():
|
|
if comment:
|
|
print(f' "{class_name}": "{weight}", # {comment}')
|
|
else:
|
|
print(f' "{class_name}": "{weight}",')
|
|
print("}")
|
|
else:
|
|
print("No class definitions found.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|