20 Feb 2010 Custom HTML-Maker for RBBCode
Tags: ruby rbbcodeHow to write a custom HTML-Maker for RBBCode
For YesPaste i use RBBCode for BBCode parsing and need to have a custom tag: code.
By default TagNode doesn’t have pure (read: non parsed) text, after reading the source code i got it:
class YesPasteHtmlMaker < RbbCode::HtmlMaker
def html_from_code_tag(node)
if node.value.nil?
lang = 'plaintext'
else
lang = node.value
end
inner_html = node.children.inject('') do |output, child|
output + make_html(child).gsub("<br/>", "\n")
end
tokens = CodeRay.scan(inner_html, lang).div(:line_numbers => :table)
return tokens
end
end
def BBCode_render(text)
html_maker = YesPasteHtmlMaker.new
parser = RbbCode::Parser.new(:html_maker => html_maker)
html = parser.parse(text)
return html
end