Commit 7cc4b3f6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #1406 from riyad/markdown-code-fixes

Markdown code fixes
parents 60ab3bea d661b893
......@@ -27,7 +27,7 @@ module GitlabMarkdownHelper
filter_html: true,
with_toc_data: true,
hard_wrap: true)
@markdown ||= Redcarpet::Markdown.new(gitlab_renderer,
@markdown = Redcarpet::Markdown.new(gitlab_renderer,
# see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
no_intra_emphasis: true,
tables: true,
......
......@@ -47,7 +47,9 @@ module Gitlab
# Note: reference links will only be generated if @project is set
def gfm(text, html_options = {})
return text if text.nil?
return text if @project.nil?
# prevents the string supplied through the _text_ argument to be altered
text = text.dup
@html_options = html_options
......@@ -78,9 +80,12 @@ module Gitlab
#
# text - Text to parse
#
# Note: reference links will only be generated if @project is set
#
# Returns parsed text
def parse(text)
text = text.gsub(REFERENCE_PATTERN) do |match|
# parse reference links
text.gsub!(REFERENCE_PATTERN) do |match|
prefix = $1 || ''
reference = $2
identifier = $3 || $4 || $5
......@@ -91,9 +96,10 @@ module Gitlab
else
match
end
end
end if @project
text = text.gsub(EMOJI_PATTERN) do |match|
# parse emoji
text.gsub!(EMOJI_PATTERN) do |match|
if valid_emoji?($2)
image_tag("emoji/#{$2}.png", size: "20x20", class: 'emoji', title: $1, alt: $1)
else
......
......@@ -247,6 +247,11 @@ describe GitlabMarkdownHelper do
it "ignores invalid emoji" do
gfm(":invalid-emoji:").should_not match(/<img/)
end
it "should work independet of reference links (i.e. without @project being set)" do
@project = nil
gfm(":+1:").should match(/<img/)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment