slugify() { printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-z0-9][^a-z0-9]*/-/g' \ -e 's/^-//' \ -e 's/-$//' \ -e 's/^$/section/' } heading_text() { tag=$1 printf '%s\n' "$2" | awk -v tag="$tag" ' function decode(s) { gsub(/"|"/, "\"", s) gsub(/'|'/, "\047", s) gsub(/<|</, "<", s) gsub(/>|>/, ">", s) gsub(/&|&/, "\\&", s) return s } { line = $0 start = index(line, "<" tag) end = index(line, "" tag ">") if (!start || !end || end < start) exit head = substr(line, start, end - start) for (i = 1; i <= length(head); i++) if (substr(head, i, 1) == ">") { close_pos = i break } if (!close_pos) exit text = substr(head, close_pos + 1) if (text !~ /) print decode(text) exit } ' } read_sections() { source=$1 slug=$2 heading_meta=$tmp/headings-$slug.tsv section_ids=$tmp/section-ids-$slug.txt subsection_meta=$tmp/subsections-$slug.tsv subsection_parents=$tmp/subsection-parents-$slug.txt : > "$heading_meta" : > "$section_ids" : > "$subsection_meta" : > "$subsection_parents" current_section= while IFS= read -r line || [ -n "$line" ]; do case $line in *'