# No character classes, since they aren't supported on every system function emit(ind, val) { print "meta[\"" FILENAME "\", \"" ind "\"]=\"" val "\"" } function erit(id, href, title) { print "reference[\"" id "\", \"href\"]=\"" href "\"" print "reference[\"" id "\", \"title\"]=\"\\\"" title "\\\"\"" } function efit(id, contents) { print "footnote[\"" id "\"]=\"" contents "\"" } title != "" && stopdesc == 0 && /^[A-Za-z]/ { startedGathering = 1 # Take only anchor text gsub(/\]\([^)]*\)/, "") gsub(/\[/, "") # Append line if (desc == "") desc = $0 else desc = desc " " $0 # Trim line to 200 characters if (length(desc) > 200) { desc = substr(desc, 1, 197) "..." stopdesc = 1 } } stopdesc == 0 && startedGathering == 1 && /^[ \t]*$/ { stopdesc = 1 } { words += NF } title == "" && /^# / { sub(/^#[ \t]*/, "") sub(/[ \t#]*$/, "") # sub(/.*/, titlef) title = $0 } /^\[[^^].*\]:/ { match($0, /^\[.+\]:/) id = substr($0, 2, RLENGTH - 3) href = substr($0, RLENGTH + 1) reftitle = "" if (match(href, /[ \t]+["'(].*[)'"]$/)) { reftitle = substr(href, RSTART) href = substr(href, 1, RSTART - 1) sub(/^[ \t]["'(]*/, "", reftitle) sub(/[)'"][ \t]*$/, "", reftitle) } sub(/^[ \t]*?[ \t]*$/, "", href) erit(id, href, reftitle) } /^\[\^[^\]]+\]:/ { match($0, /^\[\^[^\]]+\]:/) footnote_name = substr($0, 3, RLENGTH - 4) footnote_def = substr($0, RSTART + RLENGTH) sub(/^[ \t]*/, "", footnote_def) efit(footnote_name, footnote_def) } END { emit("title", title) emit("description", desc) emit("words", words) }