From: Petter Reinholdtsen Date: Wed, 31 Jan 2018 19:54:45 +0000 (+0000) Subject: Rewrite how markdown file handle endnotes/footnotes. X-Git-Tag: es-printed~524 X-Git-Url: https://pere.pagekite.me/gitweb/text-madewithcc.git/commitdiff_plain/990312413dfd7e1c16d4674e903cfe67340d0b14 Rewrite how markdown file handle endnotes/footnotes. --- diff --git a/fixup.rb b/fixup.rb index 8e8f670..6978cca 100644 --- a/fixup.rb +++ b/fixup.rb @@ -249,5 +249,27 @@ data.each_with_index do |lin, idx| end end +log 0, 'Identify and mark footnotes/endnodes' +scope="unknown" +noteblock=false +data.each_with_index do |lin, idx| + if lin =~ /^## (.+)$/ + scope=$1.gsub(" ", "-") + end + # First, mark note reference + lin.sub!(/([a-z]\.["”]?)(\d+)(\s)/, "\\1[^" + scope + "-\\2]\\3") + lin.sub!(/([a-z]\.["”]?)(\d+)$/, "\\1[^" + scope + "-\\2]") + # Next, mark note content, only between /Web Links?|Notes/ and next heading + if noteblock + lin.sub!(/^(\d+)\. /, "[^" + scope + "-\\1]: ") + if lin =~ /^##?.+/ + noteblock=false + end + end + if lin =~ /^(### Notes|Web links?)/ + noteblock=true + end +end + log 0, 'Writing processed file' File.open(dstfile, 'w') {|f| f.puts data.join("\n")}