Sha256: 984e2aad1868bb0194f9f4c78cef3f0ce3378121db1b9354946e448e05730ec9

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 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

      CODESPAN_DELIMITER = /`+/

      # Parse the codespan at the current scanner location.
      def parse_codespan
        start_line_number = @src.current_line_number
        result = @src.scan(CODESPAN_DELIMITER)
        simple = (result.length == 1)
        saved_pos = @src.save_pos

        if simple && @src.pre_match =~ /\s\Z/ && @src.match?(/\s/)
          add_text(result)
          return
        end

        if (text = @src.scan_until(/#{result}/))
          text.sub!(/#{result}\Z/, '')
          unless simple
            text = text[1..-1] if text[0..0] == ' '
            text = text[0..-2] if text[-1..-1] == ' '
          end
          @tree.children << Element.new(:codespan, text, nil, location: start_line_number)
        else
          @src.revert_pos(saved_pos)
          add_text(result)
        end
      end
      define_parser(:codespan, CODESPAN_DELIMITER, '`')

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kramdown-2.1.0 lib/kramdown/parser/kramdown/codespan.rb
kramdown-2.0.0 lib/kramdown/parser/kramdown/codespan.rb
kramdown-2.0.0.beta2 lib/kramdown/parser/kramdown/codespan.rb
kramdown-2.0.0.beta1 lib/kramdown/parser/kramdown/codespan.rb