class VimwikiMarkdown::WikiBody

Attributes

markdown_body[R]
options[R]

Public Class Methods

new(options) click to toggle source
# File lib/vimwiki_markdown/wiki_body.rb, line 10
def initialize(options)
  @options = options
end

Public Instance Methods

to_s() click to toggle source
# File lib/vimwiki_markdown/wiki_body.rb, line 14
def to_s
  hack_replace_commonmarker_proc!

  @markdown_body = get_wiki_markdown_contents
  fixlinks
  html = GitHub::Markup.render_s(
    GitHub::Markups::MARKUP_MARKDOWN,
    markdown_body,
    options: { commonmarker_opts: [:UNSAFE] }
  )

  pipeline = HTML::Pipeline.new([
    HTML::Pipeline::SyntaxHighlightFilter,
    VimwikiTOCFilter
  ], { scope: "highlight"})
  @result = pipeline.call(html)
  @result = @result[:output].to_s
  enrich_li_class!
end

Private Instance Methods

enrich_li_class!() click to toggle source
# File lib/vimwiki_markdown/wiki_body.rb, line 80
def enrich_li_class!
  syms_hash = { " ]" => 0, ".]" => 1, "o]" => 2, "O]" => 3, "X]" => 4 }
  checkbox = /<li>\s*\[[\s.oOX]\]/
  checkbox_start = /<li>\s*\[/
  @result.gsub!(checkbox) do |m|
    m.sub(checkbox_start, '<li class="done')
      .sub(/[\s.oOX\]]*$/, syms_hash) << '">'
  end
  @result
end
get_wiki_markdown_contents() click to toggle source
# File lib/vimwiki_markdown/wiki_body.rb, line 39
def get_wiki_markdown_contents
  file = File.open(options.input_file, "r")
  file.read
end
hack_replace_commonmarker_proc!() click to toggle source
# File lib/vimwiki_markdown/wiki_body.rb, line 72
def hack_replace_commonmarker_proc!
  GitHub::Markup::Markdown::MARKDOWN_GEMS["commonmarker"] = proc { |content, options: {}|
    commonmarker_opts = [:GITHUB_PRE_LANG].concat(options.fetch(:commonmarker_opts, []))
    commonmarker_exts = options.fetch(:commonmarker_exts, [:autolink, :table, :strikethrough])
    CommonMarker.render_html(content, commonmarker_opts, commonmarker_exts)
  }
end