class Doc2Text::Markdown::OdtParser

Public Class Methods

new(output, styles_xml_root = nil) click to toggle source
# File lib/doc2text/odt/markdown_odt_parser.rb, line 6
def initialize(output, styles_xml_root = nil)
  @styles_xml_root = styles_xml_root
  @output = output
  @automatic_styles = {}
end

Public Instance Methods

characters(string) click to toggle source
# File lib/doc2text/odt/markdown_odt_parser.rb, line 30
def characters(string)
  unless string.strip.empty?
    plain_text = Odt::XmlNodes::PlainText.new(string)
    @current_node.children << plain_text
  end
end
close() click to toggle source
# File lib/doc2text/odt/markdown_odt_parser.rb, line 37
def close
  @output.close
end
end_element_namespace(name, prefix = nil, uri = nil) click to toggle source
# File lib/doc2text/odt/markdown_odt_parser.rb, line 22
def end_element_namespace(name, prefix = nil, uri = nil)
  if @current_node.parent and @current_node.parent.office_text?
    @output.write @current_node.expand
    @current_node.delete
  end
  @current_node = @current_node.parent
end
logger() click to toggle source
# File lib/doc2text/odt/markdown_odt_parser.rb, line 76
def logger
  @logger ||= Logger.new(STDOUT)
end
print_tree(node) click to toggle source
start_element_namespace(name ,attrs = [], prefix = nil, uri = nil, ns = []) click to toggle source
# File lib/doc2text/odt/markdown_odt_parser.rb, line 12
def start_element_namespace(name ,attrs = [], prefix = nil, uri = nil, ns = [])
  unless @xml_root
    @xml_root = @current_node = Odt::XmlNodes::Node.create_node prefix, name, nil, attrs, self
  else
    new_node = Odt::XmlNodes::Node.create_node prefix, name, @current_node, attrs, self
    @current_node.children << new_node
    @current_node = new_node
  end
end
xpath(string) click to toggle source

Select nodes xpath style

  • supports selecting from the root node

# File lib/doc2text/odt/markdown_odt_parser.rb, line 50
def xpath(string)
  patterns = string.split '|'
  raise Doc2Text::XmlError, 'it does not support this xpath syntax' if patterns.length == 0
  result = []
  patterns.each do |pattern|
    if /^(\/[\w:\-]+)+$/ =~ pattern
      path = pattern.scan /[\w:\-]+/
      result += xpath_search_nodes(path, @xml_root)
      result += xpath_search_nodes(path, @styles_xml_root) if @styles_xml_root
    else
      raise Doc2Text::XmlError, 'it does not support this xpath syntax'
    end
  end
  result
end
xpath_search_nodes(path, xml_root) click to toggle source
# File lib/doc2text/odt/markdown_odt_parser.rb, line 66
def xpath_search_nodes(path, xml_root)
  seek_nodes = [xml_root]
  path.each_with_index do |xml_name, index|
    seek_nodes.select! { |node| node.xml_name == xml_name }
    seek_nodes = seek_nodes.map(&:children).flatten unless index == path.length - 1
    break if seek_nodes.empty?
  end
  seek_nodes
end