'
str.gsub! /\[spoilers?=(.+)\]/, '\1'
str.gsub! /\[\/spoilers?\]/, ''
str.gsub! /\n/, '
'
str
end
def parseline(str, state)
if state.last =~ /\d/ or str =~ /^\*+\s+/
parselist str, state
elsif str =~ /^(h[1-6])\.\s*(.+)\n*/
tag = $1 if $1
str = "<#{tag}>#{parseinline($2)}#{tag}>"
else
parseparagraph str, state
end
end
def parselist(str, state)
parseinline str
html = ""
if state.last == 'newline'
state.push "1"
html << ""
else
n = str.split()[0].count("*")
if n < state.last.to_i
html << '
' * (state.last.to_i - n - 1)
state[-1] = n.to_s
elsif n > state.last.to_i
html << ''
state[-1] = (state.last.to_i + 1).to_s
end
end
if str =~ /^[^\*]/
state.pop
html << "
"
return html + parseline(str, state)
end
html << str.gsub(/\*+\s+(.+)\n*/) do
"#{parseinline($1)}"
end
end
def parseparagraph(str, state)
html = ""
if state.last == 'newline'
state.push 'p'
html << ""
end
html << str.gsub(/(.+)\n*$/) do
parseinline($1)
end
if state.last == 'p' and str =~ /\n\n$/
state.pop
html << "
"
end
html
end
def parseurl(str)
str
end
end