# coding: utf-8 require "octopress-quote-tag/version" require "octopress-quote-tag/utils" require "jekyll" module Octopress module Tags module Quote class Tag < Liquid::Block FullCiteWithTitle = /(\S.*)\s+(https?:\/\/)(\S+)\s+(.+)/i FullCite = /(\S.*)\s+(https?:\/\/)(\S+)/i AuthorTitle = /([^,]+),([^,]+)/ Author = /(.+)/ def initialize(tag_name, markup, tokens) super if tag_name.strip == 'blockquote' @options = parse_legacy_markup(markup) else @options = parse_markup(%w{author title url}, markup) end end # Parse string into hash object def parse_markup(keys, markup) options = {} keys.each do |k| value = extract(markup, /\s*#{k}:\s*(("(.+?)")|('(.+?)')|(\S+))/i, [3, 5, 6]) options[k] = value end options end def extract(input, regexp, indices_to_try = [1], default = nil) thing = input.match(regexp) if thing.nil? default else indices_to_try.each do |index| return thing[index] if thing[index] end end end # Use legacy regex matching to parse markup def parse_legacy_markup(markup) options = {} if markup =~ FullCiteWithTitle options['author'] = $1 options['url'] = $2 + $3 options['title'] = $4.strip elsif markup =~ FullCite options['author'] = $1 options['url'] = $2 + $3 elsif markup =~ AuthorTitle options['author'] = $1 options['title'] = $2.strip elsif markup =~ Author options['author'] = $1 end options end def render(context) quote = "
#{Utils.parse_content(super, context).strip}" if cap = figcaption quote = "" end quote end def figcaption if @options['author'] || @options['url'] || @options['title'] "