summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2013-01-16 22:37:39 +0100
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2013-01-16 22:39:56 +0100
commit2bc78739a7aa9d7e5109281fc45dbd41a1a576d4 (patch)
tree19bf8b9cbd72f293ca3f0da7cc7f1eb1365d11a9 /lib
parent16b54178422b5e84e0ddd61a7a44306d7b164707 (diff)
downloadgitlab-ce-2bc78739a7aa9d7e5109281fc45dbd41a1a576d4.tar.gz
Fix parsing of ref-like Urls in links and images in GFM
Fixes #2166
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/markdown.rb25
-rw-r--r--lib/redcarpet/render/gitlab_html.rb4
2 files changed, 22 insertions, 7 deletions
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb
index 4694c7fc252..e7d6e3e6bd9 100644
--- a/lib/gitlab/markdown.rb
+++ b/lib/gitlab/markdown.rb
@@ -45,12 +45,11 @@ module Gitlab
# Extract pre blocks so they are not altered
# from http://github.github.com/github-flavored-markdown/
- extractions = {}
- text.gsub!(%r{<pre>.*?</pre>|<code>.*?</code>}m) do |match|
- md5 = Digest::MD5.hexdigest(match)
- extractions[md5] = match
- "{gfm-extraction-#{md5}}"
- end
+ text.gsub!(%r{<pre>.*?</pre>|<code>.*?</code>}m) { |match| extract_piece(match) }
+ # Extract links with probably parsable hrefs
+ text.gsub!(%r{<a.*?>.*?</a>}m) { |match| extract_piece(match) }
+ # Extract images with probably parsable src
+ text.gsub!(%r{<img.*?>}m) { |match| extract_piece(match) }
# TODO: add popups with additional information
@@ -58,7 +57,7 @@ module Gitlab
# Insert pre block extractions
text.gsub!(/\{gfm-extraction-(\h{32})\}/) do
- extractions[$1]
+ insert_piece($1)
end
sanitize text.html_safe, attributes: ActionView::Base.sanitized_allowed_attributes + %w(id class)
@@ -66,6 +65,18 @@ module Gitlab
private
+ def extract_piece(text)
+ @extractions ||= {}
+
+ md5 = Digest::MD5.hexdigest(text)
+ @extractions[md5] = text
+ "{gfm-extraction-#{md5}}"
+ end
+
+ def insert_piece(id)
+ @extractions[id]
+ end
+
# Private: Parses text for references and emoji
#
# text - Text to parse
diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb
index 3a430e0bf9e..4f2c86e2d41 100644
--- a/lib/redcarpet/render/gitlab_html.rb
+++ b/lib/redcarpet/render/gitlab_html.rb
@@ -27,6 +27,10 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
HTML
end
+ def link(link, title, content)
+ h.link_to_gfm(content, link, title: title)
+ end
+
def postprocess(full_document)
h.gfm(full_document)
end