-
-
Save geminorum/c8746bd193d5b00fd5ff81ebbc94cc2a to your computer and use it in GitHub Desktop.
Marked 2 Preprocessor for "lazy links"
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 | |
# 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