Created
October 19, 2013 18:56
-
-
Save ttscoff/7059952 to your computer and use it in GitHub Desktop.
Marked 2 Preprocessor for "lazy links"
This file contains 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 | |
# encoding: utf-8 | |
# Marked 2 preprocessor | |
# Allows use of `*` link references where the next [*]: href defines the link | |
# Inspired by [tidbits][*] | |
# [*]: http://tidbits.com | |
if RUBY_VERSION.to_f > 1.8 | |
input = STDIN.read.force_encoding('UTF-8') | |
else | |
input = STDIN.read | |
end | |
counter = 0 | |
while input =~ /(\[[^\]]+\]\s*\[)\*(\].*?^\[)\*\]\:/m | |
input.sub!(/(\[[^\]]+\]\s*\[)\*(\].*?^\[)\*\]\:/m) { | |
counter += 1 | |
$1 + counter.to_s + $2 + counter.to_s + "]:" | |
} | |
end | |
print input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment