Skip to content

Commit

Permalink
Refactor private method HighlightBlock#parse_options (#6822)
Browse files Browse the repository at this point in the history
Merge pull request 6822
  • Loading branch information
ashmaroli authored and jekyllbot committed Apr 16, 2018
1 parent 822d020 commit cd513da
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/jekyll/tags/highlight.rb
Expand Up @@ -65,23 +65,24 @@ def sanitized_opts(opts, is_safe)

private

OPTIONS_REGEX = %r!(?:\w="[^"]*"|\w=\w|\w)+!

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

# Split along 3 possible forms -- key="<quoted list>", key=value, or key
input.scan(OPTIONS_REGEX) do |opt|
key, value = opt.split("=")
# If a quoted list, convert to array
if value && value.include?('"')
value.delete!('"')
value = value.split
end
options[key.to_sym] = value || true
end
if options.key?(:linenos) && options[:linenos] == true
options[:linenos] = "inline"
end

options[:linenos] = "inline" if options[:linenos] == true
options
end

Expand Down

0 comments on commit cd513da

Please sign in to comment.