2017-05-19 18 views

回答

0

为了限制kramdown自动生成头的ID高达h4,你有两个选择:

写你自己的ID在这些头大于4:

##### I have a custom id 
{: #my_custom_id} 

禁用自动ID生成的那些头:

##### I don't have id! 
{::options auto_ids="false" /} 
+0

不幸的是,这些解决方案不符合我的需求。希望开发者有一天能够实现更好的一个。 – Cowboy

0

该选件没有内置功能,但可以使用猴子补丁。转换方法的来源是在这里:https://github.com/gettalong/kramdown/blob/master/lib/kramdown/converter/html.rb#L125

所以,你可以做这样的事情:

module Kramdown 
    module Converter 
    class Html 
     def convert_header(el, indent) 
     attr = el.attr.dup 
     level = output_header_level(el.options[:level]) 
     if @options[:auto_ids] && !attr['id'] && (level <= 4) 
      attr['id'] = generate_id(el.options[:raw_text]) 
     end 
     @toc << [el.options[:level], attr['id'], el.children] if attr['id'] && in_toc?(el) 
     format_as_block_html("h#{level}", attr, inner(el, indent), indent) 
     end 
    end 
    end 
end 

加入了&& (level <= 4)使得它表现你想要的方式。