views:

221

answers:

1

Hi, I want to put a new textile tag like h1. , but its name will be map.

So I found the following article but it doesn`t work on RedCloth 4.2.2

Thanks

+1  A: 

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.

agregoire
Thanks, that helped a lot... But adding new extensions http://github.com/jgarber/redcloth/blob/3a0ab611933c97aef288acf5480f7c3656c9b2c1/spec/extension_spec.rb doesn`t work...
Dimitar Vouldjeff
I mean to combine them
Dimitar Vouldjeff
Can you edit your question to give an example of what doesn't work in your code ? The specs you linked to work as expected on my machine.
agregoire