class Paru::Pandoc2Yaml
Utility class to extract YAML metadata form a markdown file in pandoc’s own markdown format.
Constants
- BLOCKS
Content’s blocks key
- 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.
- META
Meta block key
- PANDOC_2_JSON
Converter from pandoc’s markdown to pandoc’s AST JSON
- VERSION
Pandoc-type API version key
Public Class Methods
extract_metadata(input_document)
click to toggle source
Extract the YAML metadata from input document
@param input_document [String] path to input document @return [String] YAML metadata from input document on STDOUT
# File lib/paru/pandoc2yaml.rb, line 52 def self.extract_metadata input_document json = JSON.parse(PANDOC_2_JSON << File.read(input_document)) yaml = "" version, metadata = json.values_at(VERSION, META) if not metadata.empty? then metadata_document = { VERSION => version, META => metadata, BLOCKS => [] } yaml = JSON_2_PANDOC << JSON.generate(metadata_document) end yaml end