#!/usr/bin/env bash set -e -u -o pipefail -x TOPLEVEL=$(realpath "$(dirname "$0")")/.. TMPDIR="$1" : "${MMDC:=mmdc}" cd "$TOPLEVEL" # We make a mirror of the specs, since we will need to make changes to them. cp -rl spec proposals mdbook "$TMPDIR" # We use mermaid-cli to extract the mermaid from any file containing it, # and generate a new version that uses svg instead. shopt -s globstar nullglob for fname in "$TMPDIR"/**/*.md; do if grep '^```mermaid' "$fname"; then ORIG="${fname%.md}.__orig.md" mv "$fname" "$ORIG" $MMDC -i "$ORIG" -o "$fname" fi done