class Paru::PandocFilter::Document
Each file that is being filtered by pandoc is represented by a root Document
. It is the root node of the AST of the document in the file.
@!attribute meta
@return [Meta] the metadata of this document
Attributes
Public Class Methods
Source
# File lib/paru/filter/document.rb, line 94 def self.fragment(node_list) meta = Hash.new if node_list.nil? or node_list.any? {|n| n.is_block?} new_doc = Document.new CURRENT_PANDOC_VERSION, meta, [] new_doc.children = node_list else node = PandocFilter::Plain.new [] node.children = node_list new_doc = Document.new CURRENT_PANDOC_VERSION, meta, [node.to_ast] end new_doc end
Create a new Document
fragment from a list of Node
elements
@param node_list [Node a list of nodes to create a Document
fragment from
@return [Document] the document containing nodes in node_list
Source
# File lib/paru/filter/document.rb, line 57 def self.from_JSON(json) begin doc = JSON.parse json version, metadata, contents = doc.values_at(VERSION, META, BLOCKS) rescue Exception => e raise FilterError.new <<WARNING Unable to read document. Most likely cause: Paru expects a pandoc installation that has been compiled with pandoc-types >= #{CURRENT_PANDOC_VERSION.join('.')}. You can check which pandoc-types have been compiled with your pandoc installation by running `pandoc -v`. Original error message: #{e.message} WARNING end if -1 == (version <=> CURRENT_PANDOC_VERSION) if metadata.has_key?('debug_') warn <<WARNING pandoc-types API version used in document (version = #{version.join('.')}) is lower than the version of pandoc-types used by paru (#{CURRENT_PANDOC_VERSION.join('.')}. If you experience unexpected results, please try updating pandoc or downgrading paru. WARNING end end PandocFilter::Document.new version, metadata, contents end
Create a new Document
from a JSON representation of the AST
@param json [String] a JSON string representation of the AST of a document @return [Document] the newly created document
@raise [ParuFilterError] when parsing JSON AST from pandoc fails
or the parsed results do not make sense.
Source
# File lib/paru/filter/document.rb, line 115 def initialize(version = CURRENT_PANDOC_VERSION, meta = [], contents = []) @version = Version.new version @meta = Meta.new meta super contents end
Create a new Document
node based on the pandoc type version, metadata, and the contents of the document
@param version [Integer = CURRENT_PANDOC_VERSION] the version of pandoc types @param meta [Array = []] metadata @param contents [Array = []] contents
Public Instance Methods
Source
# File lib/paru/filter/document.rb, line 134 def to_JSON to_ast.to_json end
Create a JSON string representation of the AST of this Document
. Use this to write back the manipulated AST in a format that pandoc understands.