fixed 代码高亮bug
This commit is contained in:
1 parent
7805b05172
commit
39651e163a
11 files changed
+862
-15
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
|
||||
def process_css(filename, scope=''):
|
||||
if not os.path.exists(filename):
|
||||
print(f"File not found: {filename}")
|
||||
return ""
|
||||
|
||||
with open(filename, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
new_lines = []
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if not line: continue
|
||||
|
||||
# Split selector and style
|
||||
parts = line.split('{')
|
||||
if len(parts) < 2: continue
|
||||
|
||||
selector_part = parts[0].strip()
|
||||
style_part = '{' + '{'.join(parts[1:])
|
||||
|
||||
# Add scope to each selector in the comma-separated list
|
||||
selectors = [s.strip() for s in selector_part.split(',')]
|
||||
scoped_selectors = []
|
||||
|
||||
for sel in selectors:
|
||||
if scope:
|
||||
# If scope is provided (e.g., [data-theme="dark"])
|
||||
# We want: [data-theme="dark"] .chroma ...
|
||||
if sel.startswith('.bg'):
|
||||
scoped_selectors.append(f'{scope} {sel}')
|
||||
elif sel.startswith('.chroma'):
|
||||
scoped_selectors.append(f'{scope} {sel}')
|
||||
else:
|
||||
# Some styles might not start with .chroma or .bg?
|
||||
# Usually they do in Hugo Chroma output.
|
||||
scoped_selectors.append(f'{scope} {sel}')
|
||||
else:
|
||||
# No scope (Default/Day mode)
|
||||
scoped_selectors.append(sel)
|
||||
|
||||
new_selector_part = ', '.join(scoped_selectors)
|
||||
new_lines.append(new_selector_part + ' ' + style_part + '\n')
|
||||
|
||||
return ''.join(new_lines)
|
||||
|
||||
# Generate styles first
|
||||
# os.system('hugo gen chromastyles --style=friendly > friendly.css')
|
||||
# os.system('hugo gen chromastyles --style=nord > nord.css')
|
||||
|
||||
friendly = process_css('friendly.css', scope='') # Default
|
||||
nord = process_css('nord.css', scope='[data-theme="dark"]') # Night
|
||||
|
||||
with open('chroma_final.css', 'w') as f:
|
||||
f.write('/* Hugo Chroma Syntax Highlighting */\n')
|
||||
f.write('/* Day Mode (Friendly - Vibrant/Bright) */\n')
|
||||
f.write(friendly)
|
||||
f.write('\n/* Night Mode (Nord - Deep/Muted) */\n')
|
||||
f.write(nord)
|
||||
|
||||
print("chroma_final.css created.")
|
||||
Reference in new issue
Block a user