Sha256: 5f5daec329751e4e03e4fda7b54e2697b9523dab07a3df88eaf38cffdd155850

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# -*- encoding: utf-8 -*-

require 'kramdown'

module Webgen::ContentProcessor

  class KramdownHtmlConverter < ::Kramdown::Converter::Html

    def initialize(root, options, context) #:nodoc:
      super(root, options)
      @context = context
      @do_convert = if context.options.has_key?('contentprocessor.kramdown.handle_links')
                      context.options['contentprocessor.kramdown.handle_links']
                    else
                      context.website.config['contentprocessor.kramdown.handle_links']
                    end
    end

    # Convert the element tree under +root+ to HTML using the webgen +context+ object.
    def self.convert(root, options, context)
      new(root, options, context).convert(root)
    end

    def convert_a(el, indent)
      el.attr['href'] = @context.tag('relocatable', {'path' => el.attr['href']}) if @do_convert
      "<a#{html_attributes(el.attr)}>#{inner(el, indent)}</a>"
    end

    def convert_img(el, indent)
      el.attr['src'] = @context.tag('relocatable', {'path' => el.attr['src']}) if @do_convert
      "<img#{html_attributes(el.attr)} />"
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webgen-0.5.17 lib/webgen/contentprocessor/kramdown/html.rb
webgen-0.5.15 lib/webgen/contentprocessor/kramdown/html.rb