Sha256: 43fcd083d94d8d85497c35ac12461b138a6287327afa80d80c9bc8dd12d4644a

Contents?: true

Size: 1.19 KB

Versions: 17

Compression:

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

17 entries across 17 versions & 1 rubygems

Version Path
govspeak-6.5.4 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.3 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.2 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.1 lib/govspeak/kramdown_overrides.rb
govspeak-6.5.0 lib/govspeak/kramdown_overrides.rb
govspeak-6.4.0 lib/govspeak/kramdown_overrides.rb
govspeak-6.3.0 lib/govspeak/kramdown_overrides.rb
govspeak-6.2.1 lib/govspeak/kramdown_overrides.rb
govspeak-6.2.0 lib/govspeak/kramdown_overrides.rb
govspeak-6.1.1 lib/govspeak/kramdown_overrides.rb
govspeak-6.1.0 lib/govspeak/kramdown_overrides.rb
govspeak-6.0.0 lib/govspeak/kramdown_overrides.rb
govspeak-5.9.1 lib/govspeak/kramdown_overrides.rb
govspeak-5.9.0 lib/govspeak/kramdown_overrides.rb
govspeak-5.8.0 lib/govspeak/kramdown_overrides.rb
govspeak-5.7.1 lib/govspeak/kramdown_overrides.rb
govspeak-5.7.0 lib/govspeak/kramdown_overrides.rb