diff options
author | wagurano <wagurano@gmail.com> | 2018-09-23 19:57:36 +0900 |
---|---|---|
committer | wagurano <wagurano@gmail.com> | 2018-09-23 19:57:36 +0900 |
commit | f92a8bfb94310ae66afd3f891f9ecd9989969788 (patch) | |
tree | a80cde01a9d5625f78f99c3c0ab3fc8566f5d326 /guides | |
parent | 82d184839e573b2085d3ea8007f81ab31827edd0 (diff) | |
download | rails-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')
-rw-r--r-- | guides/rails_guides/markdown.rb | 2 | ||||
-rw-r--r-- | guides/rails_guides/markdown/renderer.rb | 7 |
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) |