Skip to content

Instantly share code, notes, and snippets.

@liweinan
Created January 28, 2015 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liweinan/d0a397fe1f2d92b77b3d to your computer and use it in GitHub Desktop.
Save liweinan/d0a397fe1f2d92b77b3d to your computer and use it in GitHub Desktop.
convert ulysses markdown to bbcode
# 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