Module: CommonMarkerPluggable

Defined in:
lib/commonmarker-pluggable.rb,
lib/commonmarker-pluggable/version.rb

Overview

An extension to CommonMarker that adds plugin support

CommonMarkerPluggable is a shim that adds itself to CommonMarker and intercepts calls to ‘CommonMarker.render_doc`. After a document object is created, CommonMarkerPluggable calls the `.call` method of each plugin, passing the updated document object each time.

Constant Summary collapse

VERSION =

Since:

  • 0.2.0

"0.3.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pluginsObject

Collect the plugins

Since:

  • 0.2.0



19
20
21
22
23
24
# File 'lib/commonmarker-pluggable.rb', line 19

def self.plugins
  @plugins ||= CommonMarker::Plugin.constants.reduce(Array.new) do |total,c|
                 next total unless (m = CommonMarker::Plugin.const_get(c)).is_a? Module
                 total.push m
               end
end

Instance Method Details

#render_doc(text, options = :DEFAULT, extensions = []) ⇒ Object

Render the CommonMark document

Since:

  • 0.2.0



29
30
31
32
33
34
35
# File 'lib/commonmarker-pluggable.rb', line 29

def render_doc(text, options = :DEFAULT, extensions = [])
  doc = super(text, options, extensions)
  CommonMarkerPluggable.plugins.each do |plugin|
    plugin.call doc
  end
  doc
end