【问题标题】:Redcarpet Footnotes extension not working红地毯脚注扩展不起作用
【发布时间】:2016-08-20 12:28:18
【问题描述】:

我正在尝试使链接的脚注起作用,但不知何故 Redcarpet 根本无法识别我传递给初始化程序的 footnote 扩展名。 我正在运行 Redcarpet 版本 3.3.4,它应该将脚注功能合并到 master 中,如这些帖子中所述:Post 1

Post 2

客户渲染器 类 CustomMarkdownParser

    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

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

我查看了 gem 的代码,它列出了以下扩展:

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
}

我不确定为什么不包括脚注。 我收到的输出是这样的(读 ^ 作为上标,右方括号也是上标): 大西洋[^1], [^1] 这是脚注

【问题讨论】:

    标签: ruby-on-rails ruby markdown redcarpet


    【解决方案1】:

    在您的自定义渲染器中,您覆盖处理脚注的方法,因此它们不会做任何事情。只需删除这些方法(footnote_deffootnote_ref)并让原件运行。

    此外,脚注定义的语法需要一个冒号,您似乎缺少:

    [^1]: This is the footnote
    

    【讨论】:

    • 我把那些方法注释掉了。
    • @danielbker 你似乎也有语法错误,请参阅我的更新
    • 谢谢!那里必须有不同的降价版本。我使用的备忘单在脚注定义中没有分号。哈哈。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 1970-01-01
    • 2015-01-10
    • 2012-11-19
    相关资源
    最近更新 更多