I want to put a new textile tag like h1. , but its name wi开发者_如何学Pythonll be map.
So I found the following article but it doesn`t work on RedCloth 4.2.2
Thanks
There's an example on how to use custom tags in RedCloth's specs. Basically, you put the new method you need in a module, and you pass it to the extend method of your RedCloth object.
Here's a quick example of a custom tag that puts the text it's called with in a span:
module MappingExtension
def map(opts)
html = %Q{<span class="map">#{opts[:text]}</span>\n}
end
end
require 'redcloth'
text = "The next line will contain a map:\n\nmap. map"
r = RedCloth.new text
r.extend MappingExtension
r.to_html
# "<p>The next line will contain a map:</p>\n<span class="map">map</span>\n"
If you want to use this in a Rails project, you might want to override ActionView's textilize text helper so that it extends RedCloth with your custom tag.
精彩评论