Sha256: 9577fca0ee7ae51f3720dccc8e995c9862f926af0b1ef762346c70f646c1ea19

Contents?: true

Size: 1.18 KB

Versions: 34

Compression:

Stored size: 1.18 KB

Contents

module Govspeak
  module KramdownOverrides
    # This depends on two internal parts of Kramdown.
    # 1. Parser registry (kramdown/parser/kramdown.rb#define_parser)
    # 2. Kramdown list regexes (kramdown/parser/kramdown/list.rb)
    # Updating the Kramdown gem therefore also means updating this file to to
    # match Kramdown's internals.

    def self.with_kramdown_ordered_lists_disabled
      original_list_start = list_start
      redefine_kramdown_const(:LIST_START, list_start_ul)
      list_parser = kramdown_parsers.delete(:list)
      Kramdown::Parser::Kramdown.define_parser(:list, list_start_ul)

      yield
    ensure
      redefine_kramdown_const(:LIST_START, original_list_start)
      kramdown_parsers[:list] = list_parser
    end

    def self.list_start
      Kramdown::Parser::Kramdown::LIST_START
    end

    def self.list_start_ul
      Kramdown::Parser::Kramdown::LIST_START_UL
    end

    def self.kramdown_parsers
      Kramdown::Parser::Kramdown.class_variable_get("@@parsers")
    end

    def self.redefine_kramdown_const(const, value)
      Kramdown::Parser::Kramdown.send(:remove_const, const)
      Kramdown::Parser::Kramdown.send(:const_set, const, value)
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
govspeak-6.7.5 lib/govspeak/kramdown_overrides.rb
govspeak-6.7.4 lib/govspeak/kramdown_overrides.rb
govspeak-6.7.3 lib/govspeak/kramdown_overrides.rb
govspeak-6.7.2 lib/govspeak/kramdown_overrides.rb
govspeak-6.7.1 lib/govspeak/kramdown_overrides.rb
govspeak-6.7.0 lib/govspeak/kramdown_overrides.rb
govspeak-6.6.0 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.11 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.10 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.9 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.8 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.7 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.6 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.5 lib/govspeak/kramdown_overrides.rb