Sha256: 375d4af362e21d513a5ec4d592b948c7629c917a8fdb64e86c55726d9616ab03

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

# -*- coding: utf-8 -*-
#
#--
# Copyright (C) 2009-2013 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
        result = @src.scan(CODESPAN_DELIMITER)
        simple = (result.length == 1)
        reset_pos = @src.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/, '')
          if !simple
            text = text[1..-1] if text[0..0] == ' '
            text = text[0..-2] if text[-1..-1] == ' '
          end
          @tree.children << Element.new(:codespan, text)
        else
          @src.pos = reset_pos
          add_text(result)
        end
      end
      define_parser(:codespan, CODESPAN_DELIMITER, '`')

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kramdown-1.2.0 lib/kramdown/parser/kramdown/codespan.rb
kramdown-1.1.0 lib/kramdown/parser/kramdown/codespan.rb
kramdown-1.0.2 lib/kramdown/parser/kramdown/codespan.rb
kramdown-1.0.1 lib/kramdown/parser/kramdown/codespan.rb
kramdown-1.0.0 lib/kramdown/parser/kramdown/codespan.rb