diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2014-09-01 17:47:28 +0200 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2014-09-26 01:32:33 +0200 |
commit | 390183a4269684f64e2e290869bee21cf18bf160 (patch) | |
tree | 6f23a073c64509f7ceded3bf119baf3134cb45c1 /lib | |
parent | 9cd5ff043a72001201b4c8192a45f8029ebe84ac (diff) | |
download | gitlab-ce-390183a4269684f64e2e290869bee21cf18bf160.tar.gz |
Factor out Emoji parsing using html-pipeline-gitlab
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/markdown.rb | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index 6017a4c86c1..d346acf0d32 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -1,3 +1,6 @@ +require 'html/pipeline' +require 'html/pipeline/gitlab' + module Gitlab # Custom parser for GitLab-flavored Markdown # @@ -62,6 +65,16 @@ module Gitlab insert_piece($1) end + # Context passed to the markdoqwn pipeline + markdown_context = { + asset_root: File.join(root_url, + Gitlab::Application.config.assets.prefix) + } + + result = HTML::Pipeline::Gitlab::MarkdownPipeline.call(text, + markdown_context) + text = result[:output].to_html(save_with: 0) + allowed_attributes = ActionView::Base.sanitized_allowed_attributes allowed_tags = ActionView::Base.sanitized_allowed_tags @@ -91,7 +104,6 @@ module Gitlab # Returns parsed text def parse(text, project = @project) parse_references(text, project) if project - parse_emoji(text) text end @@ -136,28 +148,6 @@ module Gitlab end end - EMOJI_PATTERN = %r{(:(\S+):)}.freeze - - def parse_emoji(text) - # parse emoji - text.gsub!(EMOJI_PATTERN) do |match| - if valid_emoji?($2) - image_tag(url_to_image("emoji/#{$2}.png"), class: 'emoji', title: $1, alt: $1, size: "20x20") - else - match - end - end - end - - # Private: Checks if an emoji icon exists in the image asset directory - # - # emoji - Identifier of the emoji as a string (e.g., "+1", "heart") - # - # Returns boolean - def valid_emoji?(emoji) - Emoji.find_by_name(emoji) - end - # Private: Dispatches to a dedicated processing method based on reference # # reference - Object reference ("@1234", "!567", etc.) |