def resolve_subs subs, type = :block, defaults = nil, subject = nil
return [] if subs.nil_or_empty?
candidates = nil
modifiers_present = SubModifierSniffRx =~ subs
subs.tr(' ', '').split(',').each do |key|
modifier_operation = nil
if modifiers_present
if (first = key.chr) == '+'
modifier_operation = :append
key = key[1..-1]
elsif first == '-'
modifier_operation = :remove
key = key[1..-1]
elsif key.end_with? '+'
modifier_operation = :prepend
key = key.chop
end
end
key = key.to_sym
if type == :inline && (key == :verbatim || key == :v)
resolved_keys = [:specialcharacters]
elsif COMPOSITE_SUBS.key? key
resolved_keys = COMPOSITE_SUBS[key]
elsif type == :inline && key.length == 1 && (SUB_SYMBOLS.key? key)
resolved_key = SUB_SYMBOLS[key]
if (candidate = COMPOSITE_SUBS[resolved_key])
resolved_keys = candidate
else
resolved_keys = [resolved_key]
end
else
resolved_keys = [key]
end
if modifier_operation
candidates ||= (defaults ? defaults.dup : [])
case modifier_operation
when :append
candidates += resolved_keys
when :prepend
candidates = resolved_keys + candidates
when :remove
candidates -= resolved_keys
end
else
candidates ||= []
candidates += resolved_keys
end
end
resolved = candidates & SUB_OPTIONS[type]
unless (candidates - resolved).empty?
invalid = candidates - resolved
warn %(asciidoctor: WARNING: invalid substitution type#{invalid.size > 1 ? 's' : ''}#{subject ? ' for ' : nil}#{subject}: #{invalid * ', '})
end
resolved
end