Class: Paru::Pandoc2Yaml

Inherits:
Object
  • Object
show all
Defined in:
lib/paru/pandoc2yaml.rb

Overview

Utility class to extract YAML metadata form a markdown file in pandoc's own markdown format.

Constant Summary collapse

PANDOC_2_JSON =

Converter from pandoc's markdown to pandoc's AST JSON

Paru::Pandoc.new {from "markdown"; to "json"}
JSON_2_PANDOC =

Converter from pandoc's AST JSON back to pandoc. Note the 'standalone' property, which is needed to output the metadata as well.

Paru::Pandoc.new {from "json"; to "markdown"; standalone}
VERSION =

Pandoc-type API version key

"pandoc-api-version"
META =

Meta block key

"meta"
BLOCKS =

Content's blocks key

"blocks"

Class Method Summary collapse

Class Method Details

.extract_metadata(input_document) ⇒ String

Extract the YAML metadata from input document

Parameters:

  • input_document (String)

    path to input document

Returns:

  • (String)

    YAML metadata from input document on STDOUT



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/paru/pandoc2yaml.rb', line 52

def self. input_document
    json = JSON.parse(PANDOC_2_JSON << File.read(input_document))
    yaml = ""

    version,  = json.values_at(VERSION, META)

    if not .empty? then
         = {
            VERSION => version, 
            META => , 
            BLOCKS => []
        }

        yaml = JSON_2_PANDOC << JSON.generate()
    end

    yaml
end