Sha256: 70c667f538be81fb12449c7493c5551edd97b04e5528c1f262e3da56a02df88f

Contents?: true

Size: 955 Bytes

Versions: 1

Compression:

Stored size: 955 Bytes

Contents

module Indexer

  class Importer

    # Import metadata from a markdown source.
    #
    module MarkdownImportation

      #
      # Markdown import procedure.
      #
      def import(source)
        if File.file?(source)
          case File.extname(source)
          when '.md', '.markdown'
            load_markdown(source)
            return true
          end
        end
        super(source) if defined?(super)
      end

      #
      # Import metadata from HTML file.
      #
      def load_markdown(file)
        require 'nokogiri'
        require 'redcarpet'

        renderer = Redcarpet::Render::HTML.new()
        markdown = Redcarpet::Markdown.new(renderer, :autolink=>true, :tables=>true, :space_after_headers=>true)
        html     = markdown.render(File.read(file))
        doc      = Nokogiri::HTML(html)

        load_html(doc)
      end

    end

    # Include mixin into Importer class.
    include MarkdownImportation

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
indexer-0.1.0 lib/indexer/importer/markdown.rb