Permalink
Browse files

Temporary added twitter embed api for blockquote.

  • Loading branch information...
yoosee committed Feb 27, 2017
1 parent 6b35a12 commit 0ec199fe9ff8d0a17bb90ffd9fa5cd77985e8cb0
Showing with 19 additions and 1 deletion.
  1. +4 −1 .gitignore
  2. +15 −0 app/services/textfi_markdown.rb
View
@@ -25,4 +25,7 @@
Gemfile.lock
/.byebug_history
/*/*.swp
*.swp
.*.swp
*~
.*~
@@ -1,6 +1,8 @@
class TextfiMarkdown < Redcarpet::Render::HTML
include Redcarpet::Render::SmartyPants
require 'json'
# def preprocess text
# end
@@ -31,6 +33,19 @@ def block_code code, language
Albino.colorize(code, language)
end
def block_quote quote
# assuming input "> https://twitter.com/...." oneline in quote
if quote.gsub(/<[^>]+>/,'') =~ /^https?:\/\/twitter\.com[\S]+/
oembed_url = "https://publish.twitter.com/oembed?url="
req = oembed_url + URI.encode(quote.gsub(/<[^>]+>/,''))
res = JSON.parse(open(req).read)
return res['html']
else
return "<blockquote>#{quote}</blockquote>"
end
end
# def codespan code
# end

0 comments on commit 0ec199f

Please sign in to comment.