From 2735b9cf97947cd0a59b0b72264d865598380879 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Sun, 24 Aug 2014 11:58:01 +0800 Subject: [PATCH] Fix guide anchor generation logic. This could use in any translation because it's not limited to `[^a-z0-9]`. Verify after this change, all guides still have same anchors. [Robin Dupret & Juanito Fatas] --- guides/rails_guides/markdown.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb index b422a80759..17035069d0 100644 --- a/guides/rails_guides/markdown.rb +++ b/guides/rails_guides/markdown.rb @@ -47,7 +47,12 @@ def dom_id(nodes) end def dom_id_text(text) - text.downcase.gsub(/\?/, '-questionmark').gsub(/!/, '-bang').gsub(/[^a-z0-9]+/, ' ').strip.gsub(/\s+/, '-') + escaped_chars = Regexp.escape('\\/`*_{}[]()#+-.!:,;|&<>^~=\'"') + + text.downcase.gsub(/\?/, '-questionmark') + .gsub(/!/, '-bang') + .gsub(/[#{escaped_chars}]+/, ' ').strip + .gsub(/\s+/, '-') end def engine -- GitLab