aboutsummaryrefslogtreecommitdiffstats
path: root/guides/rails_guides
diff options
context:
space:
mode:
authorwagurano <wagurano@gmail.com>2018-09-23 19:57:36 +0900
committerwagurano <wagurano@gmail.com>2018-09-23 19:57:36 +0900
commitf92a8bfb94310ae66afd3f891f9ecd9989969788 (patch)
treea80cde01a9d5625f78f99c3c0ab3fc8566f5d326 /guides/rails_guides
parent82d184839e573b2085d3ea8007f81ab31827edd0 (diff)
downloadrails-f92a8bfb94310ae66afd3f891f9ecd9989969788.tar.gz
rails-f92a8bfb94310ae66afd3f891f9ecd9989969788.tar.bz2
rails-f92a8bfb94310ae66afd3f891f9ecd9989969788.zip
Fix rails guides markdown.rb and renderer.rb to use custom header id
Diffstat (limited to 'guides/rails_guides')
-rw-r--r--guides/rails_guides/markdown.rb2
-rw-r--r--guides/rails_guides/markdown/renderer.rb7
2 files changed, 7 insertions, 2 deletions
diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb
index 61b371363e..a98aa8fe66 100644
--- a/guides/rails_guides/markdown.rb
+++ b/guides/rails_guides/markdown.rb
@@ -103,7 +103,7 @@ module RailsGuides
hierarchy = hierarchy[0, 3] + [node]
end
- node[:id] = dom_id(hierarchy)
+ node[:id] = dom_id(hierarchy) unless node[:id]
node.inner_html = "#{node_index(hierarchy)} #{node.inner_html}"
end
end
diff --git a/guides/rails_guides/markdown/renderer.rb b/guides/rails_guides/markdown/renderer.rb
index 8095b8c898..82bb4d6de1 100644
--- a/guides/rails_guides/markdown/renderer.rb
+++ b/guides/rails_guides/markdown/renderer.rb
@@ -29,7 +29,12 @@ HTML
# Always increase the heading level by 1, so we can use h1, h2 heading in the document
header_level += 1
- %(<h#{header_level}>#{text}</h#{header_level}>)
+ header_with_id = text.scan(/(.*){#(.*)}/)
+ unless header_with_id.empty?
+ %(<h#{header_level} id=#{header_with_id[0][1].strip}>#{header_with_id[0][0].strip}</h#{header_level}>)
+ else
+ %(<h#{header_level}>#{text}</h#{header_level}>)
+ end
end
def paragraph(text)