Sha256: d48da630d6d95b6dff8c0cacfa0d592d235be42139c46564c08bcc7ffd7b98fe

Contents?: true

Size: 1009 Bytes

Versions: 14

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true

require "kramdown-parser-gfm"

module Kramdown
  module Parser
    class GFM
      MARK_DELIMITER = %r{(==|::)+}.freeze
      MARK_MATCH = %r{#{MARK_DELIMITER}(?!\s|=|:).*?[^\s=:]#{MARK_DELIMITER}}m.freeze

      # Monkey-patch GFM initializer to add our new mark parser
      alias_method :_old_initialize, :initialize
      def initialize(source, options)
        _old_initialize(source, options)
        @span_parsers << :mark if @options[:mark_highlighting]
      end

      def parse_mark
        line_number = @src.current_line_number

        @src.pos += @src.matched_size
        el = Element.new(:html_element, "mark", {}, category: :span, line: line_number)
        @tree.children << el

        env = save_env
        reset_env(src: Kramdown::Utils::StringScanner.new(@src.matched[2..-3], line_number),
                  text_type: :text)
        parse_spans(el)
        restore_env(env)

        el
      end
      define_parser(:mark, MARK_MATCH)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bridgetown-core-1.3.4 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.3.3 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.3.2 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.3.1 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.3.0 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.3.0.beta3 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.3.0.beta2 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.3.0.beta1 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.2.0 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.2.0.beta5 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.2.0.beta4 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.2.0.beta3 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.2.0.beta2 lib/bridgetown-core/kramdown/parser/gfm.rb
bridgetown-core-1.2.0.beta1 lib/bridgetown-core/kramdown/parser/gfm.rb