Refactor private method `HighlightBlock#parse_options` (#6822)

Merge pull request 6822
This commit is contained in:
ashmaroli 2018-04-17 00:41:28 +05:30 committed by jekyllbot
parent 822d020086
commit cd513da07e
1 changed files with 14 additions and 13 deletions

View File

@ -65,23 +65,24 @@ MSG
private private
OPTIONS_REGEX = %r!(?:\w="[^"]*"|\w=\w|\w)+!
def parse_options(input) def parse_options(input)
options = {} options = {}
unless input.empty? return options if input.empty?
# Split along 3 possible forms -- key="<quoted list>", key=value, or key
input.scan(%r!(?:\w="[^"]*"|\w=\w|\w)+!) do |opt| # Split along 3 possible forms -- key="<quoted list>", key=value, or key
key, value = opt.split("=") input.scan(OPTIONS_REGEX) do |opt|
# If a quoted list, convert to array key, value = opt.split("=")
if value && value.include?("\"") # If a quoted list, convert to array
value.delete!('"') if value && value.include?('"')
value = value.split value.delete!('"')
end value = value.split
options[key.to_sym] = value || true
end end
options[key.to_sym] = value || true
end end
if options.key?(:linenos) && options[:linenos] == true
options[:linenos] = "inline" options[:linenos] = "inline" if options[:linenos] == true
end
options options
end end