def post_process(text)
return text unless allowed
space = base_indent
hash_table = {}
counter = 0
text.gsub!(/<(pre|textarea|script|style)(.*?)<\/\1>/im) do |match|
key = "<#{$1}>\x1A#{counter.to_s(4).tr('0123', "\x1B\x1C\x1D\x1E")}\x1A</#{$1}>"
counter += 1
hash_table[key] = match
key
end
text.gsub!("\n", ' ')
text.gsub!(/ +/, ' ')
text.gsub!(/ *<(\/?)(#{Texy::Html::BLOCK.keys.join('|')}|br)(>| [^>]*>) */i) do |match|
m_closing, m_tag = $1, $2
match.strip!
m_tag.downcase!
if m_tag == 'br'
"\n#{"\t" * [0, space - 1].max}#{match}"
elsif Texy::Html::EMPTY[m_tag]
"\r#{"\t" * space}#{match}\r#{"\t" * space}"
elsif m_closing == '/'
space -= 1
"\x08#{match}\n#{("\t" * space)}"
else
space += 1
"\n#{"\t" * (space - 1)}#{match}"
end
end
text.gsub!(/[\t ]+(\n|\r|$)/, '\1')
text.gsub!("\r\r", "\n")
text.gsub!("\r", "\n")
text.gsub!("\t\x08", '')
text.gsub!("\x08", '')
if line_wrap > 0
text.gsub!(/^(\t*)(.*)$/) do
$1 + $2.word_wrap(line_wrap).gsub("\n", "\n#{$1}")
end
end
hash_table.each do |from, to|
text.gsub!(from, to)
end
text
end