From 38739640bb7bb00f58ea087b02145a2174a080ec Mon Sep 17 00:00:00 2001 From: Pagwin Date: Tue, 24 Mar 2026 13:53:43 -0400 Subject: [PATCH] script to fix graphviz images, should add functionality to static gen to make this unneeded --- fix-graphviz-svg.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 fix-graphviz-svg.sh diff --git a/fix-graphviz-svg.sh b/fix-graphviz-svg.sh new file mode 100755 index 0000000..52174b3 --- /dev/null +++ b/fix-graphviz-svg.sh @@ -0,0 +1,44 @@ +# the inline fill/stroke/font-family attributes from the elements it targets. +# +# Requires: xmlstarlet +# +# Usage: +# ./svg_theme.sh input.svg # writes to stdout +# ./svg_theme.sh input.svg output.svg # writes to output.svg + +STYLE_TEXT=' + @media(prefers-color-scheme: dark){ + :root { + --color: white; + } + } + @media(prefers-color-scheme: light){ + :root { + --color: black; + } + } + ellipse, path { + fill: none; + stroke: var(--color); + } + polygon { + fill: var(--color); + stroke: var(--color); + } + text { + fill: var(--color); + font-family: sans-serif; + } + ' + +xmlstarlet ed -O \ + -N s="http://www.w3.org/2000/svg" \ + --insert "/s:svg/*[1]" --type elem --name style \ + --update "/s:svg/style" --value "$STYLE_TEXT" \ + --delete "(/s:svg//s:ellipse|/s:svg//s:path|/s:svg//s:polygon)/@fill" \ + --delete "(/s:svg//s:ellipse|/s:svg//s:path|/s:svg//s:polygon)/@stroke" \ + --delete "/s:svg//s:text/@fill" \ + --delete "/s:svg//s:text/@stroke" \ + --delete "/s:svg//s:text/@font-family" \ + --delete "(/s:svg//s:polygon)[1]"\ + "${1:--}" > "${2:-/dev/stdout}"