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,7 +27,7 @@ module GitlabMarkdownHelper | ||
| 27 | filter_html: true, | 27 | filter_html: true, |
| 28 | with_toc_data: true, | 28 | with_toc_data: true, |
| 29 | hard_wrap: true) | 29 | hard_wrap: true) |
| 30 | - @markdown ||= Redcarpet::Markdown.new(gitlab_renderer, | 30 | + @markdown = Redcarpet::Markdown.new(gitlab_renderer, |
| 31 | # see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use | 31 | # see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use |
| 32 | no_intra_emphasis: true, | 32 | no_intra_emphasis: true, |
| 33 | tables: true, | 33 | tables: true, |
lib/gitlab/markdown.rb
| @@ -47,7 +47,9 @@ module Gitlab | @@ -47,7 +47,9 @@ module Gitlab | ||
| 47 | # Note: reference links will only be generated if @project is set | 47 | # Note: reference links will only be generated if @project is set |
| 48 | def gfm(text, html_options = {}) | 48 | def gfm(text, html_options = {}) |
| 49 | return text if text.nil? | 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 | @html_options = html_options | 54 | @html_options = html_options |
| 53 | 55 | ||
| @@ -78,9 +80,12 @@ module Gitlab | @@ -78,9 +80,12 @@ module Gitlab | ||
| 78 | # | 80 | # |
| 79 | # text - Text to parse | 81 | # text - Text to parse |
| 80 | # | 82 | # |
| 83 | + # Note: reference links will only be generated if @project is set | ||
| 84 | + # | ||
| 81 | # Returns parsed text | 85 | # Returns parsed text |
| 82 | def parse(text) | 86 | def parse(text) |
| 83 | - text = text.gsub(REFERENCE_PATTERN) do |match| | 87 | + # parse reference links |
| 88 | + text.gsub!(REFERENCE_PATTERN) do |match| | ||
| 84 | prefix = $1 || '' | 89 | prefix = $1 || '' |
| 85 | reference = $2 | 90 | reference = $2 |
| 86 | identifier = $3 || $4 || $5 | 91 | identifier = $3 || $4 || $5 |
| @@ -91,9 +96,10 @@ module Gitlab | @@ -91,9 +96,10 @@ module Gitlab | ||
| 91 | else | 96 | else |
| 92 | match | 97 | match |
| 93 | end | 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 | if valid_emoji?($2) | 103 | if valid_emoji?($2) |
| 98 | image_tag("emoji/#{$2}.png", size: "20x20", class: 'emoji', title: $1, alt: $1) | 104 | image_tag("emoji/#{$2}.png", size: "20x20", class: 'emoji', title: $1, alt: $1) |
| 99 | else | 105 | else |
spec/helpers/gitlab_markdown_helper_spec.rb
| @@ -247,6 +247,11 @@ describe GitlabMarkdownHelper do | @@ -247,6 +247,11 @@ describe GitlabMarkdownHelper do | ||
| 247 | it "ignores invalid emoji" do | 247 | it "ignores invalid emoji" do |
| 248 | gfm(":invalid-emoji:").should_not match(/<img/) | 248 | gfm(":invalid-emoji:").should_not match(/<img/) |
| 249 | end | 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 | end | 255 | end |
| 251 | end | 256 | end |
| 252 | 257 |