From 990312413dfd7e1c16d4674e903cfe67340d0b14 Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Wed, 31 Jan 2018 19:54:45 +0000 Subject: [PATCH] Rewrite how markdown file handle endnotes/footnotes. --- fixup.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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")} -- 2.47.2