Created
January 28, 2015 18:04
-
-
Save liweinan/d0a397fe1f2d92b77b3d to your computer and use it in GitHub Desktop.
convert ulysses markdown to bbcode
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
# convert ulysses markdown to bbcode | |
class Main | |
$code_buffer = [] | |
$is_code_sec = false | |
def flush_code_buffer | |
$code_buffer.each do |line| | |
puts line | |
end | |
puts '[/code]' | |
$code_buffer = [] | |
$is_code_sec = false | |
end | |
def convert | |
File.open('xxx.txt').each do |line| | |
if line[0] == '#' | |
if line[1] == '#' | |
print line.gsub(/^#*\s*(.*)\s*/, '[size=xx-large]\1[/size]') | |
else | |
print line.gsub(/^#*\s*(.*)\s*/, '[size=large]\1[/size]') | |
end | |
next | |
elsif line[0] == "'" && line[1] == "'" | |
if $is_code_sec == false | |
$code_buffer << '[code]' | |
$is_code_sec = true | |
end | |
$code_buffer << line.gsub(/'+\s*(.*)\s*/, '\1') | |
next | |
else | |
flush_code_buffer if $is_code_sec == true | |
print line | |
next | |
end | |
end | |
end | |
end | |
main = Main.new | |
main.convert | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment