def filter(&block)
            @selectors = Hash.new
            @filtered_nodes = []
            @document = read_document

            @metadata = PandocFilter::Metadata.new @document.meta

            nodes_to_filter = Enumerator.new do |node_list|
                @document.each_depth_first do |node|
                    node_list << node
                end
            end

            @current_node = @document

            nodes_to_filter.each do |node|
                if @current_node.has_been_replaced?
                    @current_node = @current_node.get_replacement
                    @filtered_nodes.pop
                else
                    @current_node = node
                end

                @filtered_nodes.push @current_node

                instance_eval(&block) # run the actual filter code
            end

            write_document
        end
def filter(&block)
            @selectors = Hash.new
            @filtered_nodes = []
            @document = read_document

            @metadata = PandocFilter::Metadata.new @document.meta

            nodes_to_filter = Enumerator.new do |node_list|
                @document.each_depth_first do |node|
                    node_list << node
                end
            end

            @current_node = @document

            nodes_to_filter.each do |node|
                if @current_node.has_been_replaced?
                    @current_node = @current_node.get_replacement
                    @filtered_nodes.pop
                else
                    @current_node = node
                end

                @filtered_nodes.push @current_node

                instance_eval(&block) # run the actual filter code
            end

            write_document
        end
Create a filter using +block+. In the block you specify
 selectors and actions to be performed on selected nodes. In the
 example below, the selector is "Image", which selects all image
 nodes. The action is to prepend the contents of the image's caption
 by the string "Figure. ".

 @param block [Proc] the filter specification

 @return [JSON] a JSON string with the filtered pandoc AST

 @example Add 'Figure' to each image's caption
   input = IOString.new(File.read("my_report.md")
   output = IOString.new

   Paru::Filter.new(input, output).filter do
       with "Image" do |image|
           image.inner_markdown = "Figure. #{image.inner_markdown}"
       end
   end