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")}