Module: Syntropy::Markdown

Defined in:
lib/syntropy/markdown.rb

Overview

Markdown parsing.

Defined Under Namespace

Classes: Controller

Constant Summary collapse

FRONT_MATTER_REGEXP =
/\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
YAML_OPTS =
{
  permitted_classes: [Date],
  symbolize_names: true
}.freeze

Class Method Summary collapse

Class Method Details

.make_controller(env, atts, md) ⇒ Markdown::Controller

Creates a Markdown file contoroller for the given environment, attributes and markdown.

Parameters:

  • env (Hash)

    app environment

  • atts (Hash)

    markdown file attributes

  • md (String)

    markdown

Returns:



150
151
152
# File 'lib/syntropy/markdown.rb', line 150

def make_controller(env, atts, md)
  Controller.new(env, atts, md).to_proc
end

.parse_file(path, env) ⇒ Array

Parses the markdown file at the given path.

Parameters:

  • path (String)

    file path

Returns:

  • (Array)

    an tuple containing properties, contents



123
124
125
126
127
128
129
130
# File 'lib/syntropy/markdown.rb', line 123

def parse_file(path, env)
  md = IO.read(path) || ''
  atts = {}
  atts[:url] = path_to_url(path, env[:app_root]) if env[:app_root]
  parse_date(atts, path)

  parse_md(atts, md)
end

.parse_md(atts, md) ⇒ Array<atts, md>

Parses the markdown content, returning the attributes and cleaned up markdown.

Parameters:

  • atts (Hash)

    attributes hash

  • md (String)

    markdown file

Returns:

  • (Array<atts, md>)

    Array containing attributes and clean markdown



138
139
140
141
# File 'lib/syntropy/markdown.rb', line 138

def parse_md(atts, md)
  md = parse_content(atts, md)
  [atts, md]
end