diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-09-24 19:57:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-24 19:57:41 -0400 |
commit | 4f3eb86ffec8ebc4faea3143dda8ebb5aad74d08 (patch) | |
tree | 87447031d309e11e5ad0e21bfe346f185c6a1ee8 | |
parent | d353b0807290c0aa6fe2fb693943f0fae001aaa8 (diff) | |
parent | f92a8bfb94310ae66afd3f891f9ecd9989969788 (diff) | |
download | rails-4f3eb86ffec8ebc4faea3143dda8ebb5aad74d08.tar.gz rails-4f3eb86ffec8ebc4faea3143dda8ebb5aad74d08.tar.bz2 rails-4f3eb86ffec8ebc4faea3143dda8ebb5aad74d08.zip |
Merge pull request #33953 from wagurano/guides_markdown_custom_header_id
Fix rails guides markdown.rb and renderer.rb to use custom header id
-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) |