Module: Md2conf

Defined in:
lib/md2conf.rb,
lib/md2conf/version.rb

Overview

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.

Defined Under Namespace

Classes: ConfluenceUtil

Constant Summary collapse

VERSION =
'0.2.3'.freeze

Class Method Summary collapse

Class Method Details

.parse_markdown(markdown, cut_header: true, max_toc_level: 7, config_file: '~/.md2conf.yaml') ⇒ String

Returns Confluence Storage Format document.

Examples:

Just read a Markdown file and parse it

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

Parameters:

  • markdown (String)

    Markdown contents to convert to Confluence format.

  • cut_header (Boolean) (defaults to: true)

    Whether to cut off initial header (must start with ‘/^# /`).

  • max_toc_level (Integer) (defaults to: 7)

    Table of Contents maximum header depth.

Returns:

  • (String)

    Confluence Storage Format document.



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# 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