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

Markdown code fixes
This commit is contained in:
Dmitriy Zaporozhets 2012-09-07 21:19:31 -07:00
commit 7cc4b3f632
3 changed files with 16 additions and 5 deletions

View file

@ -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,

View file

@ -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

View file

@ -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