#!/bin/bash [[ -v VERBOSE ]] && set -x markdown_path="$1" markdown_file="$(basename "$markdown_path")" markdown_stem="$(printf %s "$markdown_file" | sed s/.md//)" build_dir="$(dirname "$markdown_path")"/.build [ -e "$build_dir" ] || mkdir "$build_dir" dep_file="$build_dir"/"$markdown_stem".d mapfile -t includes < <(grep -A2 -F '```{.include}' "$markdown_path" | awk '/include/{getline; print}') mapfile -t images < <(grep -oP '!\[.*\]\([^\)]*' "$markdown_path" | sed 's/\!\[\](//g') deps=("${includes[@]}" "${images[@]}") case "$markdown_file" in moodle-quiz.md) target_file="moodle-quiz.xml" ;; *) target_file="$(printf %s "$markdown_file" | sed s/.md/.pdf/)" ;; esac printf "${target_file}: ${markdown_file} %s\n" "${deps[*]}" > "$dep_file"