【问题标题】:How to prevent maruku from creating IDs on its own如何防止maruku自行创建ID
【发布时间】:2012-09-14 08:30:36
【问题描述】:

我在 HAML 中使用 Maruku 作为降价过滤器,它会在每个标头上创建大量无用的(对我而言)ID。

如果我有这样的事情

## This is a header

会的

<h2 id="this_is_a_header">This is a header</h2>

这在某个时候开始变得荒谬,并用一堆我不需要也不想要的 ID 填充我的 HTML,因为 Maruku 为我提供了一种提供我自己的 ID 的方法,

## {#id} This is a header

有什么方法可以阻止它的行为吗?

【问题讨论】:

    标签: haml markdown maruku


    【解决方案1】:

    Maruku is obsolete 而您应该考虑切换到 kramdown(现在获得 MIT 许可)。

    kramdown 允许您switch off auto-generation of header IDs like so:

    puts Kramdown::Document.new("# Header with spaces #", :auto_ids => false).to_html
    

    同样在kramdown中,如果你想在header上set your own ID attribute,你可以这样做:

    raw_text = "# Header with spaces #
      {: #pumice-stone}"
    
    puts Kramdown::Document.new(raw_text, :auto_ids => false).to_html
    

    输出:

    <h1 id="pumice-stone">Header with spaces</h1>
    

    请记住,自定义属性 ({: #pumice-stone}) 位于您希望将其应用到的块级元素正下方的行中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      相关资源
      最近更新 更多