Created
February 22, 2021 17:12
-
-
Save cabo/ef1a669e50df3706b9b80ae06cd515f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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