The following method takes html_encoded multiline strings and replaces all maruku blockquote elements that have been converted to html entity codes back to >
For the purpose of this implementation a maruku blockquote line is defined as a line beginning with one or more > sequences separated with optional whitespace.
def maruku_escape(text)
text.gsub(/^([\s]*\>)+/) {|match| match.gsub(/\>/, '>')}
end
The following test string was used
test_text = "<b>A bold tag</b>
<span>Some text in a span</span>
Some Markdown
> Blockquote 1
> > nested blockquote 1
> > nested blockquote 2
>> nested blockquote 3 with no spaces
Some plain text with an invalid blockquote > Some blockquote text
<i>The end in italics<i>"
And using this as follows maruku_text = maruku_escape(ERB::Util.html_escape(test_text))
Gave the following results
result = "<b>A bold tag</b>
<span>Some text in a span</span>
Some Markdown
> Blockquote 1
> > nested blockquote 1
> > nested blockquote 2
>> nested blockquote 3 with no spaces
Some plain text with an invalid blockquote > Some blockquote text
<i>The end in italics<i>
"