diff options
author | Ciro Santillli <ciro.santilli@gmail.com> | 2014-02-04 11:48:33 +0400 |
---|---|---|
committer | Ciro Santillli <ciro.santilli@gmail.com> | 2014-02-11 19:23:33 +0400 |
commit | 61748c993de8a38300c0c038cec5a07e6c324cd6 (patch) | |
tree | af9693096914e2de64eaf5bdde06f59b90317eaa /lib | |
parent | 1284f21c073e42c44b9faa7b0ad1ec90b66ca8fb (diff) |
Headers have ids and link to their own id.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redcarpet/render/gitlab_html.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb index 6da0c1d6f96..42f6316910a 100644 --- a/lib/redcarpet/render/gitlab_html.rb +++ b/lib/redcarpet/render/gitlab_html.rb @@ -8,6 +8,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML @project = @template.instance_variable_get("@project") @ref = @template.instance_variable_get("@ref") @request_path = @template.instance_variable_get("@path") + @options = options.dup super options end @@ -34,6 +35,16 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML h.link_to_gfm(content, link, title: title) end + def header(text, level) + if @options[:no_header_anchors] + "<h#{level}>#{text}</h#{level}>" + else + id = ActionController::Base.helpers.strip_tags(h.gfm(text)).downcase() \ + .gsub(/[^a-z0-9_-]/, '-').gsub(/-+/, '-').gsub(/^-/, '').gsub(/-$/, '') + "<h#{level} id=\"#{id}\">#{text}<a href=\"\##{id}\"></a></h#{level}>" + end + end + def preprocess(full_document) if @project h.create_relative_links(full_document, @project, @ref, @request_path, is_wiki?) |