Sha256: 205cdb4b6e3da0c75895aa2f54210a04d2d6f2140f0d29d4d9b39d5e0281c729

Contents?: true

Size: 934 Bytes

Versions: 1

Compression:

Stored size: 934 Bytes

Contents

require 'active_support/inflector'
require 'github/markup'
require 'html/pipeline'

class VimwikiMarkdown::WikiBody

  def initialize(options)
    @options = options
  end

  def to_s
    @markdown_body = get_wiki_markdown_contents
    fixlinks
    github_markup = GitHub::Markup.render('README.markdown', markdown_body)
    pipeline = HTML::Pipeline.new [
      HTML::Pipeline::SyntaxHighlightFilter,
      HTML::Pipeline::TableOfContentsFilter
    ]
    result = pipeline.call(github_markup)
    result[:output].to_s
  end


  private

  attr_reader :options, :markdown_body

  def get_wiki_markdown_contents
    file = File.open(options.input_file, "r")
    file.read
  end

  def fixlinks
    #convert wiki_links to markdown links
    # [This link](http://example.net/)
    @markdown_body.gsub!(/\[\[(.*?)\]\]/) do
      link_title = Regexp.last_match[1]
      "[#{link_title}](#{link_title.parameterize}.html)"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vimwiki_markdown-0.1.3 lib/vimwiki_markdown/wiki_body.rb