def self.parse_style_attribute(attributes, reader = nil)
original_style = attributes['style']
raw_style = attributes[1]
if raw_style && !raw_style.include?(' ') && Compliance.shorthand_property_syntax
type = :style
collector = []
parsed = {}
save_current = lambda {
if collector.empty?
if type != :style
warn %(asciidoctor: WARNING:#{reader.nil? ? nil : " #{reader.prev_line_info}:"} invalid empty #{type} detected in style attribute)
end
else
case type
when :role, :option
parsed[type] ||= []
parsed[type].push collector.join
when :id
if parsed.has_key? :id
warn %(asciidoctor: WARNING:#{reader.nil? ? nil : " #{reader.prev_line_info}:"} multiple ids detected in style attribute)
end
parsed[type] = collector.join
else
parsed[type] = collector.join
end
collector = []
end
}
raw_style.each_char do |c|
if c == '.' || c == '#' || c == '%'
save_current.call
case c
when '.'
type = :role
when '#'
type = :id
when '%'
type = :option
end
else
collector.push c
end
end
if type == :style
parsed_style = attributes['style'] = raw_style
else
save_current.call
if parsed.has_key? :style
parsed_style = attributes['style'] = parsed[:style]
else
parsed_style = nil
end
if parsed.has_key? :id
attributes['id'] = parsed[:id]
end
if parsed.has_key? :role
attributes['role'] = parsed[:role] * ' '
end
if parsed.has_key? :option
(options = parsed[:option]).each do |option|
attributes[%(#{option}-option)] = ''
end
if (existing_opts = attributes['options'])
attributes['options'] = (options + existing_opts.split(',')) * ','
else
attributes['options'] = options * ','
end
end
end
[parsed_style, original_style]
else
attributes['style'] = raw_style
[raw_style, original_style]
end
end