Sha256: 6aafcdfab8ecaabb2d84fe1e6ba2770d07d34f6ffa2654a4dd7a695fb63cf397

Contents?: true

Size: 1.59 KB

Versions: 8

Compression:

Stored size: 1.59 KB

Contents

# -*- coding: utf-8 -*-
#
#--
# Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
#
# This file is part of kramdown.
#
# kramdown is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#++
#

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

8 entries across 8 versions & 3 rubygems

Version Path
gitdown-0.0.2 lib/kramdown/parser/kramdown/codespan.rb
gitdown-0.0.1 lib/kramdown/parser/kramdown/codespan.rb
kramdown-0.13.4 lib/kramdown/parser/kramdown/codespan.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/kramdown-0.13.3/lib/kramdown/parser/kramdown/codespan.rb
kramdown-0.13.3 lib/kramdown/parser/kramdown/codespan.rb
kramdown-0.13.2 lib/kramdown/parser/kramdown/codespan.rb
kramdown-0.13.1 lib/kramdown/parser/kramdown/codespan.rb
kramdown-0.12.0 lib/kramdown/parser/kramdown/codespan.rb