diff options
author | Connor Shea <connor.james.shea@gmail.com> | 2016-11-23 23:53:56 +0300 |
---|---|---|
committer | Connor Shea <connor.james.shea@gmail.com> | 2016-11-24 00:01:29 +0300 |
commit | 24057f4e3a5dde185c4f01ed94e45bc5bc2f7521 (patch) | |
tree | ab73362348f2a27964d689a6d135129dd095ad3f /lib | |
parent | c647e973ec7cbba99d8fca0982a296e727c45c0d (diff) |
Fix anchors.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/helpers_.rb | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/helpers_.rb b/lib/helpers_.rb index 3de84452..f4364f13 100644 --- a/lib/helpers_.rb +++ b/lib/helpers_.rb @@ -11,16 +11,15 @@ require 'rouge/plugins/redcarpet' class HTML < Redcarpet::Render::HTML include Rouge::Plugins::Redcarpet - PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u def header(text, header_level) - # https://gitlab.com/gitlab-org/gitlab-ce/blob/0676c5c7140ccf5b809eddab79b6fb78b7db0a66/lib/banzai/filter/table_of_contents_filter.rb#L29-32 - anchor = text.downcase - anchor.gsub!(PUNCTUATION_REGEXP, '') # remove punctuation - anchor.tr!(' ', '-') # replace spaces with dash + # https://github.com/cookpad/garage/blob/c817733e382c734eedba743e9103cd8a124f24eb/lib/garage/docs/anchor_building.rb#L24 + anchor = text.gsub(/\s+/, '-').gsub(/<\/?[^>]*>/, '').downcase + # https://github.com/rails/rails/blob/e491b2c06329afb3c989261a2865d2a93c8b84b8/activesupport/lib/active_support/inflector/transliterate.rb#L86 + anchor.gsub!(/[^a-z0-9\-_]+/i, '-') anchor.squeeze!('-') # replace multiple dashes with one - "<h#{header_level} id='#{anchor}'>#{text} <a class='anchor' href='##{anchor}' title='Permalink'>¶</a></h#{header_level}>" + %(<h#{header_level} id='#{anchor}'>#{text} <a class='anchor' href='##{anchor}' title='Permalink'>¶</a></h#{header_level}>) end def image(link, title, alt_text) |