Created
June 30, 2014 22:49
-
-
Save ttscoff/090de25f020b11385495 to your computer and use it in GitHub Desktop.
Search a concatenated Marked index file for include comments and adjust [[image.jpg]] tags to point to paths relative to included file
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/ruby | |
# Marked 2 preprocessor | |
# Search a concatenated Marked index file for include comments and adjust | |
# [[image.jpg]] tags to point to paths relative to included file | |
# Update: Converts [[tags]] to Markdown image tags using the generated paths | |
input = STDIN.read | |
includes = [] | |
output = input.split(/\n/).map! { |line| | |
if line =~ /<!-- include \[(.*?)\]/ | |
dir = File.dirname($1) | |
includes.push(dir) unless includes.include?(dir) | |
elsif line =~ /<!-- end include \[(.*?)\]/ | |
includes = includes.slice(0,includes.index(File.dirname($1))) | |
end | |
# line.gsub(/\[\[(.*?\|)?(.*?\.(?:png|svg|gif|jpg))\]\]/, "[[\\1#{includes[-1]}/\\2]]") | |
line.gsub(/\[\[((.*?)\|)?(.*?\.(?:png|svg|gif|jpg))\]\]/, "") | |
}.join("\n") | |
$stdout.print output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment