Skip to content

Instantly share code, notes, and snippets.

@cabo
Created February 22, 2021 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cabo/ef1a669e50df3706b9b80ae06cd515f7 to your computer and use it in GitHub Desktop.
Save cabo/ef1a669e50df3706b9b80ae06cd515f7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -Ku -i.bak
fail "Usage: section1.rb foo.md" unless ARGV.size == 1
s = ARGF.read
SECTIONS_RE = /Section(?:s? (?:[\w.]+, )*[\w.]+,? and)? [\w.]+/
puts s.gsub(/(#{SECTIONS_RE}\s+of)\s+{{([-\w.]+}})/) { "{{#$1 #$2" }
# Note that we don't fix "Section 3 and 5 of {{foo}}" into "Sections 3 and 5 of {{foo}"
# -- that must be done manually, with all the not so easy to recognize section references
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment