Skip to content

Commit d5a8127

Browse files
Copilotdsyme
andauthored
Add mermaid diagram sanitization to wiki push step (#284)
* Initial plan * Add Mermaid diagram sanitization step to push-wiki safe-output job Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
1 parent fed4a49 commit d5a8127

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

workflows/agentic-wiki-writer.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,50 @@ safe-outputs:
7272
CONTENT=$(printf '%s' "$entry" | base64 -d | jq -r '.value')
7373
printf '%s\n' "$CONTENT" > "$FILENAME"
7474
done
75+
- name: Sanitize Mermaid diagrams
76+
run: |
77+
python3 - <<'EOF'
78+
import re, glob
79+
80+
def fix_mermaid_block(block):
81+
# Remove backtick markdown-string syntax from node labels.
82+
# GitHub's wiki renderer does not support mermaid markdown strings
83+
# (e.g. A["`text`"]), causing "Unable to render rich display" errors.
84+
# Pattern: "` inside_bt ` after_bt " -> " inside_bt after_bt "
85+
def fix_backtick_label(m):
86+
inside_bt = m.group(1)
87+
after_bt = m.group(2)
88+
combined = re.sub(
89+
r'\s+', ' ',
90+
(inside_bt + ' ' + after_bt).replace('\\n', ' ')
91+
).strip()
92+
return '"' + combined + '"'
93+
94+
fixed = re.sub(r'"`([^`]*)`([^"]*)"', fix_backtick_label, block)
95+
# Fix any remaining \n escape sequences in labels (replace with space)
96+
fixed = re.sub(r'\\n', ' ', fixed)
97+
return fixed
98+
99+
def fix_file(path):
100+
with open(path, encoding='utf-8') as f:
101+
content = f.read()
102+
parts = re.split(r'(```mermaid[^\n]*\n.*?```)', content, flags=re.DOTALL)
103+
fixed = ''.join(
104+
fix_mermaid_block(p) if p.startswith('```mermaid') else p
105+
for p in parts
106+
)
107+
if fixed != content:
108+
with open(path, 'w', encoding='utf-8') as f:
109+
f.write(fixed)
110+
return True
111+
return False
112+
113+
changed = [f for f in glob.glob('*.md') if fix_file(f)]
114+
if changed:
115+
print(f'Fixed Mermaid syntax in: {", ".join(changed)}')
116+
else:
117+
print('No Mermaid syntax issues found')
118+
EOF
75119
- name: Commit and push
76120
run: |
77121
git config user.name "github-actions[bot]"

0 commit comments

Comments
 (0)