Class: Kramdown::Parser::Html::ElementConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/kramdown-gist/parser/html.rb

Overview

Monkey-patch the standard Kramdown HTML post-processor so that all references to embedded gists are replaced with a specialized :gist Element.

Instance Method Summary collapse

Instance Method Details

#convert_script(el) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hook into the <script> tag conversion process so that we have a chance to generate :gist elements based on the src attribute of the tag.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kramdown-gist/parser/html.rb', line 39

define_method(:convert_script) do |el|
  if %r{^https?://gist.github.com/([0-9a-fA-F]+)\.js$} =~ el.attr['src']
    # We're in business, convert el to a gist element
    set_basics(el, :gist)
    el.value = $1
    el.children.clear
    el.attr.delete('src')
  else
    # Fall back to the original method
    original_convert_script.bind(self).call(el)
  end
end