mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-03-31 04:52:12 +02:00
closes GitHub issue #57
This commit is contained in:
parent
bc826f07fe
commit
9de917fb23
3 changed files with 27 additions and 17 deletions
|
@ -1,21 +1,12 @@
|
||||||
module MarkdownHelper
|
module MarkdownHelper
|
||||||
|
|
||||||
def markdown(content)
|
def markdown(content)
|
||||||
md = Redcarpet::Markdown.new(FlavoredMarkdown,
|
md = Redcarpet::Markdown.new(FlavoredMarkdown, MARKDOWN_OPTS)
|
||||||
filter_html: true,
|
|
||||||
escape_html: true,
|
|
||||||
no_images: true,
|
|
||||||
no_styles: true,
|
|
||||||
safe_links_only: true,
|
|
||||||
xhtml: false,
|
|
||||||
hard_wrap: true,
|
|
||||||
no_intra_emphasis: true,
|
|
||||||
tables: true,
|
|
||||||
fenced_code_blocks: true,
|
|
||||||
autolink: true,
|
|
||||||
disable_indented_code_blocks: true,
|
|
||||||
strikethrough: true,
|
|
||||||
superscript: false)
|
|
||||||
Sanitize.fragment(md.render(content), EVIL_TAGS).html_safe
|
Sanitize.fragment(md.render(content), EVIL_TAGS).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def strip_markdown(content)
|
||||||
|
md = Redcarpet::Markdown.new(Redcarpet::Render::StripDown, MARKDOWN_OPTS)
|
||||||
|
CGI.unescape_html Sanitize.fragment(md.render(content), EVIL_TAGS)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,5 +1,6 @@
|
||||||
class Services::Twitter < Service
|
class Services::Twitter < Service
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
|
include MarkdownHelper
|
||||||
|
|
||||||
def provider
|
def provider
|
||||||
"twitter"
|
"twitter"
|
||||||
|
@ -27,8 +28,8 @@ class Services::Twitter < Service
|
||||||
|
|
||||||
def prepare_tweet(answer)
|
def prepare_tweet(answer)
|
||||||
# TODO: improve this.
|
# TODO: improve this.
|
||||||
question_content = answer.question.content
|
question_content = strip_markdown answer.question.content
|
||||||
answer_content = answer.content
|
answer_content = strip_markdown answer.content
|
||||||
answer_url = show_user_answer_url(
|
answer_url = show_user_answer_url(
|
||||||
id: answer.id,
|
id: answer.id,
|
||||||
username: answer.user.screen_name,
|
username: answer.user.screen_name,
|
||||||
|
|
18
config/initializers/redcarpet.rb
Normal file
18
config/initializers/redcarpet.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
require 'redcarpet/render_strip'
|
||||||
|
|
||||||
|
MARKDOWN_OPTS = {
|
||||||
|
filter_html: true,
|
||||||
|
escape_html: true,
|
||||||
|
no_images: true,
|
||||||
|
no_styles: true,
|
||||||
|
safe_links_only: true,
|
||||||
|
xhtml: false,
|
||||||
|
hard_wrap: true,
|
||||||
|
no_intra_emphasis: true,
|
||||||
|
tables: true,
|
||||||
|
fenced_code_blocks: true,
|
||||||
|
autolink: true,
|
||||||
|
disable_indented_code_blocks: true,
|
||||||
|
strikethrough: true,
|
||||||
|
superscript: false
|
||||||
|
}
|
Loading…
Reference in a new issue