]> pere.pagekite.me Git - text-madewithcc.git/commitdiff
Rewrite how markdown file handle endnotes/footnotes.
authorPetter Reinholdtsen <pere@hungry.com>
Wed, 31 Jan 2018 19:54:45 +0000 (19:54 +0000)
committerPetter Reinholdtsen <pere@hungry.com>
Thu, 22 Feb 2018 18:12:08 +0000 (18:12 +0000)
fixup.rb

index 8e8f670a20575cce829c5cba2a57a9fc07e612c6..6978cca088dc02760534930b5b913979ea7e6193 100644 (file)
--- 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")}