Skip to content

Commit 4f3eb86

Browse files
authored
Merge pull request rails#33953 from wagurano/guides_markdown_custom_header_id
Fix rails guides markdown.rb and renderer.rb to use custom header id
2 parents d353b08 + f92a8bf commit 4f3eb86

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

guides/rails_guides/markdown.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def generate_structure
103103
hierarchy = hierarchy[0, 3] + [node]
104104
end
105105

106-
node[:id] = dom_id(hierarchy)
106+
node[:id] = dom_id(hierarchy) unless node[:id]
107107
node.inner_html = "#{node_index(hierarchy)} #{node.inner_html}"
108108
end
109109
end

guides/rails_guides/markdown/renderer.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ def header(text, header_level)
2929
# Always increase the heading level by 1, so we can use h1, h2 heading in the document
3030
header_level += 1
3131

32-
%(<h#{header_level}>#{text}</h#{header_level}>)
32+
header_with_id = text.scan(/(.*){#(.*)}/)
33+
unless header_with_id.empty?
34+
%(<h#{header_level} id=#{header_with_id[0][1].strip}>#{header_with_id[0][0].strip}</h#{header_level}>)
35+
else
36+
%(<h#{header_level}>#{text}</h#{header_level}>)
37+
end
3338
end
3439

3540
def paragraph(text)

0 commit comments

Comments
 (0)