From f92a8bfb94310ae66afd3f891f9ecd9989969788 Mon Sep 17 00:00:00 2001 From: wagurano Date: Sun, 23 Sep 2018 19:57:36 +0900 Subject: Fix rails guides markdown.rb and renderer.rb to use custom header id --- guides/rails_guides/markdown.rb | 2 +- guides/rails_guides/markdown/renderer.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'guides/rails_guides') 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 - %(#{text}) + header_with_id = text.scan(/(.*){#(.*)}/) + unless header_with_id.empty? + %(#{header_with_id[0][0].strip}) + else + %(#{text}) + end end def paragraph(text) -- cgit v1.2.3