In my rails app, I am using Kramdown to parse Markdown. I want to extend the functionality of the convert_a
method in the HTML converter. Part of this involves accessing the database, but it is dependent on a parameter in the URL. Because I am not directly calling the method that I am overriding I cannot simply pass the method the params
hash. Is there a way to access this hash, or even just get the current URL in a module in the lib
directory?
to give a bit more context, the method call is in a helper method here:
# in app/helpers/myhelper.rb
def to_html(text)
Kramdown::Document.new(text, parse_block_html: true).to_custom_html
end
and here is the file in which I override the convert_a
:
# in lib/custom_html.rb
class CustomHtml < Kramdown::Converter::Html
def convert_a(el, indent)
# use params[:foo] to make query
format_as_span_html(el.type, el.attr, inner(el, indent))
end
end
Edit:
To give a bit more context on where the overrided method is called. I am not extremely familiar with the Kramdown codebase, however it seems that when to_custom_html
is called the following bit of code is run inside of Kramdown.rb
:
output, warnings = Converter.const_get(name).convert(@root, @options)
which subsequently calls convert_#{el.type}
on the internal kramdown elements.