11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/bluedoc/sml/rules/heading.rb', line 11
def self.to_html(node, opts = {})
renderer = opts[:renderer]
title = (renderer.children_to_html(node) || "").strip
heading_tag = tag_name(node)
title_length = title.length
min_length = title_length * 0.3
words_length = /[a-z0-9]/i.match(title)&.length || 0
= title.gsub(/[^a-z0-9]+/i, "-").downcase.gsub(/^\-|\-$/, "")
if title_length - .length > min_length
= Digest::MD5.hexdigest(title.strip)[0..8]
end
attrs = attributes(node)
nid_attr = name_by_attrs(attrs)
if title.blank?
%(<#{heading_tag}#{nid_attr}>#{title}</#{heading_tag}>)
else
%(<#{heading_tag} id="#{}"#{nid_attr}><a href="##{}" class="heading-anchor">#</a>#{title}</#{heading_tag}>)
end
end
|