Commit 90f587f4ee854fe14f0f7efcf012dfc1a0666dcd
1 parent
880a233e
Exists in
master
and in
4 other branches
Move the entire `gfm` method to Gitlab::Markdown, which will be a module now
Showing
1 changed file
with
1 additions
and
34 deletions
Show diff stats
app/helpers/gitlab_markdown_helper.rb
1 | module GitlabMarkdownHelper | 1 | module GitlabMarkdownHelper |
2 | - # Replaces references (i.e. @abc, #123, !456, ...) in the text with links to | ||
3 | - # the appropriate items in Gitlab. | ||
4 | - # | ||
5 | - # text - the source text | ||
6 | - # html_options - extra options for the reference links as given to link_to | ||
7 | - # | ||
8 | - # note: reference links will only be generated if @project is set | ||
9 | - # | ||
10 | - # see Gitlab::Markdown for details on the supported syntax | ||
11 | - def gfm(text, html_options = {}) | ||
12 | - return text if text.nil? | ||
13 | - return text if @project.nil? | ||
14 | - | ||
15 | - # Extract pre blocks so they are not altered | ||
16 | - # from http://github.github.com/github-flavored-markdown/ | ||
17 | - extractions = {} | ||
18 | - text.gsub!(%r{<pre>.*?</pre>|<code>.*?</code>}m) do |match| | ||
19 | - md5 = Digest::MD5.hexdigest(match) | ||
20 | - extractions[md5] = match | ||
21 | - "{gfm-extraction-#{md5}}" | ||
22 | - end | ||
23 | - | ||
24 | - # TODO: add popups with additional information | ||
25 | - | ||
26 | - parser = Gitlab::Markdown.new(@project, html_options) | ||
27 | - text = parser.parse(text) | ||
28 | - | ||
29 | - # Insert pre block extractions | ||
30 | - text.gsub!(/\{gfm-extraction-(\h{32})\}/) do | ||
31 | - extractions[$1] | ||
32 | - end | ||
33 | - | ||
34 | - sanitize text.html_safe, attributes: ActionView::Base.sanitized_allowed_attributes + %w(id class ) | ||
35 | - end | 2 | + include Gitlab::Markdown |
36 | 3 | ||
37 | # Use this in places where you would normally use link_to(gfm(...), ...). | 4 | # Use this in places where you would normally use link_to(gfm(...), ...). |
38 | # | 5 | # |