Sha256: 4a0f225cff42988adc2bf738e84d9e3c97bab0aa9e09e120499db2b1215d33c9

Contents?: true

Size: 1.69 KB

Versions: 10

Compression:

Stored size: 1.69 KB

Contents

# -*- coding: utf-8; frozen_string_literal: true -*-
#
#--
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
#
# This file is part of kramdown which is licensed under the MIT.
#++
#

module Kramdown
  module Parser
    class Kramdown

      # Parse the string +str+ and extract all attributes and add all found attributes to the hash
      # +opts+.
      def parse_attribute_list(str, opts)
        return if str.strip.empty? || str.strip == ':'
        style_attr = []
        attrs = str.scan(ALD_TYPE_ANY)
        attrs.each do |key, sep, val, style_key, style_val, ref, id_and_or_class, _, _|
          if ref
            (opts[:refs] ||= []) << ref
          elsif id_and_or_class
            id_and_or_class.scan(ALD_TYPE_ID_OR_CLASS).each do |id_attr, class_attr|
              if class_attr
                opts[IAL_CLASS_ATTR] = "#{opts[IAL_CLASS_ATTR]} #{class_attr}".lstrip
              else
                opts['id'] = id_attr
              end
            end
          elsif style_key
            style_attr << (style_key + style_val)
          else
            val.gsub!(/\\(\}|#{sep})/, "\\1")
            if /\Astyle\Z/i =~ key
              style_attr << val
            else
              opts[key] = val
            end
          end
        end
        (opts['style'] = style_attr.join(' ')) unless style_attr.empty?
        warning("No or invalid attributes found in IAL/ALD content: #{str}") if attrs.empty?
      end

      ALD_TYPE_STYLE_ATTR = /%((?:--)?#{ALD_ID_NAME}:)\s*?((?:\\\}|\\;|[^\};])*?;)/
      remove_const(:ALD_TYPE_ANY)
      ALD_TYPE_ANY = /(?:\A|\s)(?:#{ALD_TYPE_KEY_VALUE_PAIR}|#{ALD_TYPE_STYLE_ATTR}|#{ALD_TYPE_REF}|#{ALD_TYPE_ID_OR_CLASS_MULTI})(?=\s|\Z)/

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
darkmouun-3.2.3 lib/darkmouun/kramdown/parser/kramdown/extensions.rb
darkmouun-3.2.2 lib/darkmouun/kramdown/parser/kramdown/extensions.rb
darkmouun-3.2.1 lib/darkmouun/kramdown/parser/kramdown/extensions.rb
darkmouun-3.2.0 lib/darkmouun/kramdown/parser/kramdown/extensions.rb
darkmouun-3.1.1 lib/darkmouun/kramdown/parser/kramdown/extensions.rb
darkmouun-2.3.1 lib/darkmouun/kramdown/parser/kramdown/extensions.rb
darkmouun-2.3.0 lib/darkmouun/kramdown/parser/kramdown/extensions.rb
darkmouun-2.2.1 lib/darkmouun/kramdown/parser/kramdown/extensions.rb
darkmouun-2.2.0 lib/darkmouun/kramdown/parser/kramdown/extensions.rb
darkmouun-2.1.1 lib/darkmouun/kramdown/parser/kramdown/extensions.rb