class Octopress::Pygments::OptionsParser
Attributes
input[RW]
Public Class Methods
new(markup)
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 9 def initialize(markup) @input = markup.strip end
Public Instance Methods
boolize(str)
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 123 def boolize(str) return nil if str.nil? return true if str == true || str =~ (/(true|t|yes|y|1)$/i) return false if str == false || str =~ (/(false|f|no|n|0)$/i) || str.strip.size > 1 return str end
clean_markup()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 13 def clean_markup input.sub(/\s*lang:\s*\S+/i,'') .sub(/\s*title:\s*(("(.+?)")|('(.+?)')|(\S+))/i,'') .sub(/\s*url:\s*(\S+)/i,'') .sub(/\s*link_text:\s*(("(.+?)")|('(.+?)')|(\S+))/i,'') .sub(/\s*mark:\s*\d\S*/i,'') .sub(/\s*linenos:\s*\w+/i,'') .sub(/\s*start:\s*\d+/i,'') .sub(/\s*end:\s*\d+/i,'') .sub(/\s*range:\s*\d+-\d+/i,'') .sub(/\s*escape:\s*\w+/i,'') end
endline()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 96 def endline if range range.last else num = extract(/\s*end:\s*(\d+)/i) num = num.to_i unless num.nil? num end end
escape()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 58 def escape boolize(extract(/\s*escape:\s*(\w+)/i)) end
extract(regexp, indices_to_try = [1], default = nil)
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 112 def extract(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
lang()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 42 def lang extract(/\s*lang:\s*(\S+)/i) end
linenos()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 54 def linenos boolize(extract(/\s*linenos:\s*(\w+)/i)) end
link_text()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 82 def link_text extract(/\s*link[-_]text:\s*(("(.+?)")|('(.+?)')|(\S+))/i, [3, 5, 6], 'link') end
marks()
click to toggle source
Public: Matches pattern for line marks and returns array of line
numbers to mark
Example input
Input: "mark:1,5-10,2" Output: [1,2,5,6,7,8,9,10]
Returns an array of integers corresponding to the lines which are
indicated as marked
# File lib/octopress-pygments/options_parser.rb, line 71 def marks marks = [] if input =~ / *mark:(\d\S*)/i marks = $1.gsub /(\d+)-(\d+)/ do ($1.to_i..$2.to_i).to_a.join(',') end marks = marks.split(',').collect {|s| s.to_i}.sort end marks end
parse_markup(defaults = {})
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 26 def parse_markup(defaults = {}) options = { lang: lang, url: url, title: title, linenos: linenos, marks: marks, link_text: link_text, start: start, end: endline, escape: escape } options = options.delete_if { |k,v| v.nil? } defaults.merge(options) end
range()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 106 def range if input.match(/ *range:(\d+)-(\d+)/i) [$1.to_i, $2.to_i] end end
start()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 86 def start if range range.first else num = extract(/\s*start:\s*(\d+)/i) num = num.to_i unless num.nil? num end end
title()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 50 def title extract(/\s*title:\s*(("(.+?)")|('(.+?)')|(\S+))/i, [3, 5, 6]) end
url()
click to toggle source
# File lib/octopress-pygments/options_parser.rb, line 46 def url extract(/\s*url:\s*(("(.+?)")|('(.+?)')|(\S+))/i, [3, 5, 6]) end