danielbker danielbker - 3 months ago 33
Markdown Question

Redcarpet Footnotes extension not working

I am trying to get linked footnotes to work but somehow Redcarpet simply is not recognizing the

footnote
extension I am passing into the initialiser.
I am running Redcarpet version 3.3.4, which should have the footnotes functionality merged into master as discussed in these posts: Post 1

Post 2

Customer Renderer
class CustomMarkdownParser < Redcarpet::Render::HTML

include ActionView::Helpers::UrlHelper
include ActionView::Helpers::AssetTagHelper
include AbstractController::Rendering

def block_code(code, language)
Pygments.highlight(code, lexer: language)
end

def parse_media_link(link)
end


def image(link, title, alt_text)
end

def link(link, title, content)
end

#def footnote_def(content, number)
#end

#def footnote_ref(number)
#end
end


markdown function in application_helper

def md_parser(content)
puts "Parsing Markdown"
renderer = CustomMarkdownParser.new(
hard_wrap: true,
filter_html: true,
with_toc_data: true)

options ={

}

markdown = Redcarpet::Markdown.new(renderer,
autolink: true, # detect links and wrap them in link tags
no_intra_emphasis: true, # ensures _ inside words are not repolaced with <em> tags
disable_indented_code_blocks: true, # does not convert lines prefixed with 4 spaces
fenced_code_blocks: true,
lax_spacing: true,
strikethrough: true,
footnotes: true,
superscript: true,
tables: true,
underline: true
)

markdown.render(content).html_safe
end


I had a look atthe gem's code and it lists the following extensions:

EXTENSION_MAP = {
# old name => new name
:autolink => :autolink,
:fenced_code => :fenced_code_blocks,
:filter_html => :filter_html,
:hard_wrap => :hard_wrap,
:prettify => :prettify,
:lax_htmlblock => :lax_spacing,
:no_image => :no_images,
:no_intraemphasis => :no_intra_emphasis,
:no_links => :no_links,
:filter_styles => :no_styles,
:safelink => :safe_links_only,
:space_header => :space_after_headers,
:strikethrough => :strikethrough,
:tables => :tables,
:generate_toc => :with_toc_data,
:xhtml => :xhtml,

# old names with no new mapping
:gh_blockcode => nil,
:no_tables => nil,
:smart => nil,
:strict => nil
}


I am not sure why footnotes is not included.
The output i receive is this (read ^ as superscript, the closing square bracket is superscripted as well):
Atlantic[^1],
[^1] This is the footnote

Answer

In your custom renderer you override the methods handling footnotes so they don’t do anything. Just remove those methods (footnote_def and footnote_ref) and allow the originals to run.

Additionally, the syntax for footnote definitions requires a colon which you seem to be missing:

[^1]: This is the footnote