I’m trying to use Redcarpet’s :with_toc_data as an option, and it works.
It inserts the ‘a name=”whatever”‘ to headers (h1, h2, etc).
My Site users can choose a setting to have links open in a new window (or not).
Setting this in the code is easy:
if request.cookies["open_links_in_new_window"].nil? || (request.cookies["open_links_in_new_window"] == "yes")
target = "_blank" + rand(1000000).to_s
else
target = ""
end
This is called after the options and extensions are set via:
options = {}
extensions = {whatever}
renderer = OurHTML.new(options)
markdown = Redcarpet::Markdown.new(renderer, extensions)
markdown.render(text).html_safe
What I would like to do is set the target to nil or “” when an href begins with a “#”.
Basically I want to be able to have a TOC in a markdown block.
hrefs that start with “#” will get no target, normal hrefs will get a random target, if the users chose that option.
Unlike the “target” if/then, I can’t figure out how to test for the actual href value individually.
I know this is a really specific and weird question.
Any advice would be awesome.