-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathfix_slide_separators.py
More file actions
57 lines (48 loc) · 1.63 KB
/
fix_slide_separators.py
File metadata and controls
57 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
import re
import sys
def fix_slide_separators(filename):
with open(filename, 'r') as f:
content = f.read()
lines = content.split('\n')
new_lines = []
# Track if we're in YAML header
yaml_count = 0
i = 0
while i < len(lines):
line = lines[i]
# Count YAML delimiters
if line.strip() == '---':
yaml_count += 1
if yaml_count <= 2: # Keep first two --- for YAML header
new_lines.append(line)
else:
# This is a slide separator
# Look ahead to see what follows
next_non_empty = None
j = i + 1
while j < len(lines) and lines[j].strip() == '':
j += 1
if j < len(lines):
next_non_empty = lines[j]
# If next line starts with ##, it's already a heading
if next_non_empty and next_non_empty.strip().startswith('##'):
# Just remove the ---
pass
else:
# Replace --- with ##
new_lines.append('##')
else:
new_lines.append(line)
i += 1
# Join lines back
return '\n'.join(new_lines)
if __name__ == '__main__':
if len(sys.argv) > 1:
filename = sys.argv[1]
fixed_content = fix_slide_separators(filename)
with open(filename, 'w') as f:
f.write(fixed_content)
print(f"Fixed {filename}")
else:
print("Usage: fix_slide_separators.py <filename>")