2011-05-30 00:30:16 -04:00
|
|
|
#
|
2011-06-15 18:31:22 -04:00
|
|
|
# Author: Brandon Mathis
|
2011-07-17 17:23:41 -04:00
|
|
|
# A full rewrite based on the work of: Josediaz Gonzalez - https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/blockquote.rb
|
2011-05-30 00:30:16 -04:00
|
|
|
#
|
2011-06-19 15:14:01 -04:00
|
|
|
# Outputs a string with a given attribution as a quote
|
|
|
|
#
|
2011-07-17 17:23:41 -04:00
|
|
|
# {% blockquote Bobby Willis http://google.com/search?q=pants the search for bobby's pants %}
|
2011-06-19 15:14:01 -04:00
|
|
|
# Wheeee!
|
|
|
|
# {% endblockquote %}
|
|
|
|
# ...
|
|
|
|
# <blockquote>
|
|
|
|
# <p>Wheeee!</p>
|
|
|
|
# <footer>
|
2011-07-17 17:23:41 -04:00
|
|
|
# <strong>Bobby Willis</strong><cite><a href="http://google.com/search?q=pants">The Search For Bobby's Pants</a>
|
2011-06-19 15:14:01 -04:00
|
|
|
# </blockquote>
|
|
|
|
#
|
2011-07-11 11:37:38 -04:00
|
|
|
require './plugins/titlecase.rb'
|
|
|
|
|
2011-05-30 00:30:16 -04:00
|
|
|
module Jekyll
|
|
|
|
|
|
|
|
class Blockquote < Liquid::Block
|
2011-07-22 11:47:23 -04:00
|
|
|
FullCiteWithTitle = /(\S.*)\s+(https?:\/\/)(\S+)\s+(.+)/i
|
|
|
|
FullCite = /(\S.*)\s+(https?:\/\/)(\S+)/i
|
|
|
|
Author = /(.+)/
|
2011-05-30 00:30:16 -04:00
|
|
|
|
|
|
|
def initialize(tag_name, markup, tokens)
|
|
|
|
@by = nil
|
|
|
|
@source = nil
|
|
|
|
@title = nil
|
|
|
|
if markup =~ FullCiteWithTitle
|
|
|
|
@by = $1
|
|
|
|
@source = $2 + $3
|
|
|
|
@title = $4.titlecase
|
|
|
|
elsif markup =~ FullCite
|
|
|
|
@by = $1
|
|
|
|
@source = $2 + $3
|
|
|
|
elsif markup =~ Author
|
2011-07-22 11:47:23 -04:00
|
|
|
if $1 =~ /([^,]+),([^,]+)/
|
|
|
|
@by = $1
|
|
|
|
@title = $2.titlecase
|
|
|
|
else
|
|
|
|
@by = $1
|
|
|
|
end
|
2011-05-30 00:30:16 -04:00
|
|
|
end
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def render(context)
|
2012-05-22 12:30:26 -04:00
|
|
|
quote = paragraphize(super)
|
2011-07-19 16:32:57 -04:00
|
|
|
author = "<strong>#{@by.strip}</strong>" if @by
|
2011-06-22 18:53:17 -04:00
|
|
|
if @source
|
|
|
|
url = @source.match(/https?:\/\/(.+)/)[1].split('/')
|
|
|
|
parts = []
|
|
|
|
url.each do |part|
|
|
|
|
if (parts + [part]).join('/').length < 32
|
|
|
|
parts << part
|
|
|
|
end
|
|
|
|
end
|
|
|
|
source = parts.join('/')
|
|
|
|
source << '/…' unless source == @source
|
|
|
|
end
|
2011-07-22 11:47:23 -04:00
|
|
|
if !@source.nil?
|
2011-12-11 17:24:32 -05:00
|
|
|
cite = " <cite><a href='#{@source}'>#{(@title || source)}</a></cite>"
|
2011-07-22 11:47:23 -04:00
|
|
|
elsif !@title.nil?
|
2011-12-11 17:24:32 -05:00
|
|
|
cite = " <cite>#{@title}</cite>"
|
2011-07-22 11:47:23 -04:00
|
|
|
end
|
|
|
|
blockquote = if @by.nil?
|
2011-07-19 16:32:57 -04:00
|
|
|
quote
|
2011-07-22 11:47:23 -04:00
|
|
|
elsif cite
|
2011-07-19 16:32:57 -04:00
|
|
|
"#{quote}<footer>#{author + cite}</footer>"
|
2011-05-30 00:30:16 -04:00
|
|
|
else
|
2011-07-19 16:32:57 -04:00
|
|
|
"#{quote}<footer>#{author}</footer>"
|
2011-05-30 00:30:16 -04:00
|
|
|
end
|
2011-07-22 11:47:23 -04:00
|
|
|
"<blockquote>#{blockquote}</blockquote>"
|
2011-05-30 00:30:16 -04:00
|
|
|
end
|
2011-06-22 18:53:17 -04:00
|
|
|
|
|
|
|
def paragraphize(input)
|
2012-05-24 11:24:37 -04:00
|
|
|
"<p>#{input.lstrip.rstrip.gsub(/\n\n/, '</p><p>').gsub(/\n/, '<br/>')}</p>"
|
2011-06-22 18:53:17 -04:00
|
|
|
end
|
2011-05-30 00:30:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Liquid::Template.register_tag('blockquote', Jekyll::Blockquote)
|