Commit 7cc4b3f632dbd2ab9c0096e4f5e6fcd0b4c6b071
Exists in
master
and in
4 other branches
Merge pull request #1406 from riyad/markdown-code-fixes
Markdown code fixes
Showing
3 changed files
with
16 additions
and
5 deletions
Show diff stats
app/helpers/gitlab_markdown_helper.rb
| ... | ... | @@ -27,7 +27,7 @@ module GitlabMarkdownHelper |
| 27 | 27 | filter_html: true, |
| 28 | 28 | with_toc_data: true, |
| 29 | 29 | hard_wrap: true) |
| 30 | - @markdown ||= Redcarpet::Markdown.new(gitlab_renderer, | |
| 30 | + @markdown = Redcarpet::Markdown.new(gitlab_renderer, | |
| 31 | 31 | # see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use |
| 32 | 32 | no_intra_emphasis: true, |
| 33 | 33 | tables: true, | ... | ... |
lib/gitlab/markdown.rb
| ... | ... | @@ -47,7 +47,9 @@ module Gitlab |
| 47 | 47 | # Note: reference links will only be generated if @project is set |
| 48 | 48 | def gfm(text, html_options = {}) |
| 49 | 49 | return text if text.nil? |
| 50 | - return text if @project.nil? | |
| 50 | + | |
| 51 | + # prevents the string supplied through the _text_ argument to be altered | |
| 52 | + text = text.dup | |
| 51 | 53 | |
| 52 | 54 | @html_options = html_options |
| 53 | 55 | |
| ... | ... | @@ -78,9 +80,12 @@ module Gitlab |
| 78 | 80 | # |
| 79 | 81 | # text - Text to parse |
| 80 | 82 | # |
| 83 | + # Note: reference links will only be generated if @project is set | |
| 84 | + # | |
| 81 | 85 | # Returns parsed text |
| 82 | 86 | def parse(text) |
| 83 | - text = text.gsub(REFERENCE_PATTERN) do |match| | |
| 87 | + # parse reference links | |
| 88 | + text.gsub!(REFERENCE_PATTERN) do |match| | |
| 84 | 89 | prefix = $1 || '' |
| 85 | 90 | reference = $2 |
| 86 | 91 | identifier = $3 || $4 || $5 |
| ... | ... | @@ -91,9 +96,10 @@ module Gitlab |
| 91 | 96 | else |
| 92 | 97 | match |
| 93 | 98 | end |
| 94 | - end | |
| 99 | + end if @project | |
| 95 | 100 | |
| 96 | - text = text.gsub(EMOJI_PATTERN) do |match| | |
| 101 | + # parse emoji | |
| 102 | + text.gsub!(EMOJI_PATTERN) do |match| | |
| 97 | 103 | if valid_emoji?($2) |
| 98 | 104 | image_tag("emoji/#{$2}.png", size: "20x20", class: 'emoji', title: $1, alt: $1) |
| 99 | 105 | else | ... | ... |
spec/helpers/gitlab_markdown_helper_spec.rb
| ... | ... | @@ -247,6 +247,11 @@ describe GitlabMarkdownHelper do |
| 247 | 247 | it "ignores invalid emoji" do |
| 248 | 248 | gfm(":invalid-emoji:").should_not match(/<img/) |
| 249 | 249 | end |
| 250 | + | |
| 251 | + it "should work independet of reference links (i.e. without @project being set)" do | |
| 252 | + @project = nil | |
| 253 | + gfm(":+1:").should match(/<img/) | |
| 254 | + end | |
| 250 | 255 | end |
| 251 | 256 | end |
| 252 | 257 | ... | ... |