From 61748c993de8a38300c0c038cec5a07e6c324cd6 Mon Sep 17 00:00:00 2001 From: Ciro Santillli Date: Tue, 4 Feb 2014 08:48:33 +0100 Subject: Headers have ids and link to their own id. --- lib/redcarpet/render/gitlab_html.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib') 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] + "#{text}" + else + id = ActionController::Base.helpers.strip_tags(h.gfm(text)).downcase() \ + .gsub(/[^a-z0-9_-]/, '-').gsub(/-+/, '-').gsub(/^-/, '').gsub(/-$/, '') + "#{text}" + end + end + def preprocess(full_document) if @project h.create_relative_links(full_document, @project, @ref, @request_path, is_wiki?) -- cgit v1.2.1