开发者

Extending MaRuKu to generate raw html tags, md_html escapes html

I'm working in the Insitiki code and trying to extend the maruku syntax to generate some custom html tags.

Example:

|youtube 0FWPr6u8YF |

Should print the html code as follows:

<object data='http://www.youtube.com/v/01hcB2zmMqM' style='width:425px; height:350px;' type='application/x-shockwave-flash'><param name='movie' value='http://www.youtube.com/v/01hcB2zmMqM'/></object>

Thus giving me a youtube embbeded video.

To make it work I followed this tutorial http://maruku.rubyforge.org/extending/extensions.html and looked at maruku docum开发者_JAVA技巧entation.

THE PROBLEM is, using the maruku method:

context.push(doc.md_html("<p>raw html</p>"))

The resulting html code is escaped, so what I get is verbatim text and not the raw html that I wanted.

I tried changing the strategy and using something like:

context.push(doc.md_el(:raw_html,[],:raw_html => "<p> raw raw raw </p>")

To no use ... what I get now is: REXML could not parse this XML/HTML:

Found nothing on this issue, the maruku docs are really thin (or I'm really bad at searching)... this guy seems to have a similar problem textile and maruku problem

Any help is appreciated.


I can't seem to reproduce this bug under maruku version 0.6.0.

context.push(doc.md_html("<p>raw html</p>"))

Generates the expected result, with no html escaping. Maybe the problem has been fixed?

Maruku is rather strict about the HTML you are generating though, so maybe it doesn't like something about the actual code you are inserting instead of <p>raw html</p>

For future reference, this is how I managed to register a span extension to replace {{var_name}} with <span class='text_var' text_var='var_name'>&nbsp;</span> under maruku 0.6.0:

TextVar = /(\{\{)(.+)(\}\})/

MaRuKu::In::Markdown.register_span_extension(
  :chars => 123, #ASCII ordinal of {
  :regexp => TextVar,
  :handler => lambda do |doc, src, con|
    m = src.read_regexp3(TextVar)
    var_name = m.captures.compact[1]
    string = "<span class='text_var' text_var='#{var_name}'>&nbsp;</span>"
    con.push doc.md_html(string)
    #con.push doc.md_html("<p>raw html</p>")
    true
end)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜