lib/kramdown/converter/base.rb in kramdown-0.13.8 vs lib/kramdown/converter/base.rb in kramdown-0.14.0
- old
+ new
@@ -130,17 +130,34 @@
end
# Return +true+ if the header element +el+ should be used for the table of contents (as
# specified by the +toc_levels+ option).
def in_toc?(el)
- @options[:toc_levels].include?(el.options[:level])
+ @options[:toc_levels].include?(el.options[:level]) and ((not el.attr['class'].split.include?('no_toc')) rescue true)
end
# Return the output header level given a level.
#
# Uses the +header_offset+ option for adjusting the header level.
def output_header_level(level)
[[level + @options[:header_offset], 6].min, 1].max
+ end
+
+ # Extract the code block/span language from the attributes.
+ def extract_code_language(attr)
+ if attr['class'] && attr['class'] =~ /\blanguage-\w+\b/
+ attr['class'].scan(/\blanguage-(\w+)\b/).first.first
+ end
+ end
+
+ # See #extract_code_language
+ #
+ # *Warning*: This version will modify the given attributes if a language is present.
+ def extract_code_language!(attr)
+ lang = extract_code_language(attr)
+ attr['class'] = attr['class'].sub(/\blanguage-\w+\b/, '').strip if lang
+ attr.delete('class') if lang && attr['class'].empty?
+ lang
end
# Generate an unique alpha-numeric ID from the the string +str+ for use as a header ID.
#
# Uses the option +auto_id_prefix+: the value of this option is prepended to every generated