class Octopress::Tags::CaptionedImageTag::CaptionExtractor

Constants

QDOUBLE
QSINGLE

Public Class Methods

extract(markup) click to toggle source
# File lib/octo-captioned-image/caption_extractor.rb, line 9
def self.extract(markup)

        # find the first quote instance
  c, start = caption_start(markup)

  partial = markup[start+1..-1]
        fin = -1
        caption = nil

  partial.chars.each_with_index do |v,i|
        if v == c && partial[i-1] != '\\'
                fin = i
                caption = partial[0..fin-1]
                break
        end
  end

  # remove the comment string from @mutable_markup
  remainder = markup[0..(start-1)]+markup[(start+fin+2)..-1]

  # swap " -> " and ' -> ' in caption
  if c == QDOUBLE
    caption.gsub!("\\#{QDOUBLE}", """)
  else
    caption.gsub!("\\#{QSINGLE}", "'")
  end

        return caption, remainder
end

Private Class Methods

caption_start(markup) click to toggle source
# File lib/octo-captioned-image/caption_extractor.rb, line 41
def self.caption_start(markup)
  di = markup.index(QDOUBLE)
  si = markup.index(QSINGLE)

  if di && si && di < si
    return QDOUBLE, di
  elsif di && si && si < di
    return QSINGLE, si
  elsif di && !si
    return QDOUBLE, di
  elsif si && !di
    return QSINGLE, si
  else
    raise "Could not find a quoted caption in #{@markup}"
  end
end