Sha256: c31d7b6598f5f0de8081cb045ba537dcb602c951848121d73723cf72ac563958

Contents?: true

Size: 1.79 KB

Versions: 74

Compression:

Stored size: 1.79 KB

Contents

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

module Kramdown
  module Parser
    class Kramdown

      EMPHASIS_START = /(?:\*\*?|__?)/

      # Parse the emphasis at the current location.
      def parse_emphasis
        start_line_number = @src.current_line_number
        saved_pos = @src.save_pos

        result = @src.scan(EMPHASIS_START)
        element = (result.length == 2 ? :strong : :em)
        type = result[0..0]

        if (type == '_' && @src.pre_match =~ /[[:alpha:]-]\z/) || @src.check(/\s/) ||
            @tree.type == element || @stack.any? {|el, _| el.type == element}
          add_text(result)
          return
        end

        sub_parse = lambda do |delim, elem|
          el = Element.new(elem, nil, nil, :location => start_line_number)
          stop_re = /#{Regexp.escape(delim)}/
          found = parse_spans(el, stop_re) do
            (@src.pre_match[-1, 1] !~ /\s/) &&
              (elem != :em || !@src.match?(/#{Regexp.escape(delim*2)}(?!#{Regexp.escape(delim)})/)) &&
              (type != '_' || !@src.match?(/#{Regexp.escape(delim)}[[:alnum:]]/)) && el.children.size > 0
          end
          [found, el, stop_re]
        end

        found, el, stop_re = sub_parse.call(result, element)
        if !found && element == :strong && @tree.type != :em
          @src.revert_pos(saved_pos)
          @src.pos += 1
          found, el, stop_re = sub_parse.call(type, :em)
        end
        if found
          @src.scan(stop_re)
          @tree.children << el
        else
          @src.revert_pos(saved_pos)
          @src.pos += result.length
          add_text(result)
        end
      end
      define_parser(:emphasis, EMPHASIS_START, '\*|_')

    end
  end
end

Version data entries

74 entries across 71 versions & 18 rubygems

Version Path
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/kramdown-1.13.1/lib/kramdown/parser/kramdown/emphasis.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/kramdown-1.13.1/lib/kramdown/parser/kramdown/emphasis.rb
kramdown-1.13.1 lib/kramdown/parser/kramdown/emphasis.rb
kramdown-1.13.0 lib/kramdown/parser/kramdown/emphasis.rb
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/kramdown-1.12.0/lib/kramdown/parser/kramdown/emphasis.rb
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/kramdown-1.12.0/lib/kramdown/parser/kramdown/emphasis.rb
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/kramdown-1.12.0/lib/kramdown/parser/kramdown/emphasis.rb
logstash-filter-base64-1.0.3 vendor/bundle/jruby/2.2.0/gems/kramdown-1.12.0/lib/kramdown/parser/kramdown/emphasis.rb
logstash-filter-delta-1.0.0 vendor/bundle/jruby/2.2.0/gems/kramdown-1.12.0/lib/kramdown/parser/kramdown/emphasis.rb
logstash-filter-base64-1.0.2 vendor/bundle/jruby/2.3.0/gems/kramdown-1.12.0/lib/kramdown/parser/kramdown/emphasis.rb
logstash-filter-base64-1.0.1 vendor/bundle/jruby/2.3.0/gems/kramdown-1.12.0/lib/kramdown/parser/kramdown/emphasis.rb
logstash-filter-base64-1.0.0 vendor/bundle/jruby/2.3.0/gems/kramdown-1.12.0/lib/kramdown/parser/kramdown/emphasis.rb
kramdown-1.12.0 lib/kramdown/parser/kramdown/emphasis.rb
kramdown-1.11.1 lib/kramdown/parser/kramdown/emphasis.rb