lix/doc/manual/process-includes.sh
eldritch horrors 65d544b1a6 build: extract make "functions" into scripts
we'll want to use these for the meson builds, and probably eventually
rewrite them in something that isn't plain shell. diffoscope confirms
that out/share and doc/share are equal before and after these changes

Change-Id: I49aa418fc8615cad86d67328e08c28a7405ec952
2024-03-30 14:26:47 +00:00

13 lines
516 B
Bash
Executable file

#!/bin/sh
set -euo pipefail
# re-implement mdBook's include directive to make it usable for terminal output and for proper @docroot@ substitution
(grep '{{#include' "$1" || true) | while read -r line; do
filename="$(dirname "$1")/$(printf "$line" | sed 's/{{#include \(.*\)}}/\1/')"
test -f "$filename" || ( echo "#include-d file '$filename' does not exist." >&2; exit 1; )
matchline="$(printf "$line" | sed 's|/|\\/|g')"
sed -i "/$matchline/r $filename" "$2"
sed -i "s/$matchline//" "$2"
done