]> cat aescling's git repositories - mastodon.git/commitdiff
Add fallback section ID with ToC (#11941)
authorYamagishi Kazutoshi <ykzts@desire.sh>
Mon, 23 Sep 2019 15:25:10 +0000 (00:25 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 23 Sep 2019 15:25:10 +0000 (17:25 +0200)
app/lib/toc_generator.rb

index 351675a5cd0877f1646e9b68ee45bb5e893abbc4..0c8f766ca42fdde089afdac7795c3ab5cbf81963 100644 (file)
@@ -45,7 +45,7 @@ class TOCGenerator
     parsed_html.traverse do |node|
       next unless TARGET_ELEMENTS.include?(node.name)
 
-      anchor = node['id'] || node.text.parameterize
+      anchor = node['id'] || node.text.parameterize.presence || 'sec'
       @slugs[anchor] += 1
       anchor = "#{anchor}-#{@slugs[anchor]}" if @slugs[anchor] > 1