-
-
Save mdaisuke/8018849 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
ARGV.each do |fn| | |
lines = File.readlines(fn) | |
hiki = lines.map { |l| | |
l.sub(/^(#+)\s/){ '!'*($1.length) + ' ' }. | |
sub(/^(-+)\s/){ '*'*($1.length) + ' ' }. | |
gsub(/\!\[([^\]]+)\]\(([^\)]+)\)/){ $2[0..3] == 'http' ? $2 : ('http://goos-lokka.heroku.com' + $2) }. # picture | |
gsub(/\[([^\]]+)\]\(([^\)]+)\)/, '[[\1|\2]]'). # url | |
gsub(/\*\*([^*]*)\*\*/, "'''\\1'''"). | |
sub(/^ /, ' '). | |
gsub(/`([^`]+)`/, '\'\'\1\'\''). | |
gsub('<span style="color:green">', 'Green: '). | |
gsub('<span style="color:red">', 'Red: '). | |
gsub(/<span style="color:.*">/, ''). | |
gsub('</span>', '') | |
} | |
# コードブロック中の空行を修正 | |
hiki.each_with_index { |l, idx| | |
if l == "\n" && hiki[idx-1].match(/^\s/) && hiki.size > idx+1 && hiki[idx+1].match(/^\s/) | |
hiki[idx] = " \n" | |
end | |
} | |
hiki_fn = fn.sub(/\.md$/, '.hiki') | |
open(hiki_fn, "w") { |f| f.write(hiki.join) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment