module Md2conf

Processes markdown and converts it to Confluence Storage Format.

The main workload is done by redcarpet gem, which generates an almost ready-to-use XHTML output. But there's some more magic performed by ConfluenceUtil class afterwards.

Constants

VERSION

Public Class Methods

parse_markdown(markdown, cut_header: true, max_toc_level: 7, config_file: '~/.md2conf.yaml') click to toggle source

@example Just read a Markdown file and parse it

Md2conf.parse_markdown File.read './README.md'

@param [String] markdown Markdown contents to convert to Confluence format. @param [Boolean] cut_header Whether to cut off initial header (must start with `/^# /`). @param [Integer] max_toc_level Table of Contents maximum header depth.

@return [String] Confluence Storage Format document.

# File lib/md2conf.rb, line 191
def self.parse_markdown(markdown, cut_header: true, max_toc_level: 7, config_file: '~/.md2conf.yaml')
  if cut_header && markdown.start_with?('# ')
    markdown = markdown.lines.drop(1).join
  end

  redcarpet_options = {
    tables:             true,
    fenced_code_blocks: true,
    autolink:           true,
    strikethrough:      true,
  }

  md         = Redcarpet::Markdown.new(Redcarpet::Render::XHTML.new, redcarpet_options)
  html       = md.render(markdown)
  confluence = ConfluenceUtil.new(html, max_toc_level, config_file)
  confluence.parse
end