Sha256: 2505ceee4fd3d44b1b9c6d3dd687de2c2d3fdb2b45188de3a560494e28ea33bc

Contents?: true

Size: 1.86 KB

Versions: 17

Compression:

Stored size: 1.86 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.
#++
#

require 'kramdown/parser/kramdown/blank_line'
require 'kramdown/parser/kramdown/extensions'
require 'kramdown/parser/kramdown/eob'
require 'kramdown/parser/kramdown/paragraph'

module Kramdown
  module Parser
    class Kramdown

      CODEBLOCK_START = INDENT
      CODEBLOCK_MATCH = /(?:#{BLANK_LINE}?(?:#{INDENT}[ \t]*\S.*\n)+(?:(?!#{IAL_BLOCK_START}|#{EOB_MARKER}|^#{OPT_SPACE}#{LAZY_END_HTML_STOP}|^#{OPT_SPACE}#{LAZY_END_HTML_START})^[ \t]*\S.*\n)*)*/

      # Parse the indented codeblock at the current location.
      def parse_codeblock
        start_line_number = @src.current_line_number
        data = @src.scan(self.class::CODEBLOCK_MATCH)
        data.gsub!(/\n( {0,3}\S)/, ' \\1')
        data.gsub!(INDENT, '')
        @tree.children << new_block_el(:codeblock, data, nil, location: start_line_number)
        true
      end
      define_parser(:codeblock, CODEBLOCK_START)

      FENCED_CODEBLOCK_START = /^~{3,}/
      FENCED_CODEBLOCK_MATCH = /^((~){3,})\s*?((\S+?)(?:\?\S*)?)?\s*?\n(.*?)^\1\2*\s*?\n/m

      # Parse the fenced codeblock at the current location.
      def parse_codeblock_fenced
        if @src.check(self.class::FENCED_CODEBLOCK_MATCH)
          start_line_number = @src.current_line_number
          @src.pos += @src.matched_size
          el = new_block_el(:codeblock, @src[5], nil, location: start_line_number, fenced: true)
          lang = @src[3].to_s.strip
          unless lang.empty?
            el.options[:lang] = lang
            el.attr['class'] = "language-#{@src[4]}"
          end
          @tree.children << el
          true
        else
          false
        end
      end
      define_parser(:codeblock_fenced, FENCED_CODEBLOCK_START)

    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
kramdown-2.5.1 lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.5.0 lib/kramdown/parser/kramdown/codeblock.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/kramdown-2.4.0/lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.4.0 lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.3.2 lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.3.1 lib/kramdown/parser/kramdown/codeblock.rb
daqing_kramdown-2.3.2 lib/kramdown/parser/kramdown/codeblock.rb
daqing_kramdown-2.3.1 lib/kramdown/parser/kramdown/codeblock.rb
zine_brewer-1.5.0 vendor/bundle/ruby/2.7.0/gems/kramdown-2.3.0/lib/kramdown/parser/kramdown/codeblock.rb
zine_brewer-1.3.0 vendor/bundle/ruby/2.7.0/gems/kramdown-2.3.0/lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.3.0 lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.2.1 lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.2.0 lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.1.0 lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.0.0 lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.0.0.beta2 lib/kramdown/parser/kramdown/codeblock.rb
kramdown-2.0.0.beta1 lib/kramdown/parser/kramdown/codeblock.rb