Module: Doc2Text::Odt::XmlNodes::Text

Included in:
H, List, ListItem, P, Span
Defined in:
lib/doc2text/odt/odt_xml_namespaces.rb

Defined Under Namespace

Classes: H, LineBreak, List, ListItem, P, Span

Instance Method Summary collapse

Instance Method Details

#fetch_style(elem_style) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/doc2text/odt/odt_xml_namespaces.rb', line 103

def fetch_style(elem_style)
  if elem_style
    elem_style.children.select { |style_property| style_property.xml_name == 'style:text-properties' }.each { |text_property|
      text_property.attrs.each { |attr|
        if attr.prefix == 'style'
          if attr.localname == 'font-style-complex' && attr.value == 'italic'
            @enclosing_style << '_'
          elsif attr.localname == 'font-weight-complex' && attr.value == 'bold'
            @enclosing_style << '**'
          end
        end
      }
    }
  end
end

#fetch_style?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/doc2text/odt/odt_xml_namespaces.rb', line 99

def fetch_style?
  true
end

#find_style(style_name) ⇒ Object



119
120
121
122
123
# File 'lib/doc2text/odt/odt_xml_namespaces.rb', line 119

def find_style(style_name)
  styles = @xml_parser.xpath '/office:document-content/office:automatic-styles/style:style'
  styles.find { |style| style.attrs.index { |attr| attr.prefix == 'style' && attr.localname == 'family' } &&
      style.attrs.index { |attr| attr.prefix == 'style' && attr.localname == 'name' && attr.value == style_name } }
end

#initialize(parent = nil, attrs = [], prefix = nil, name = nil, markdown_odt_parser = nil) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/doc2text/odt/odt_xml_namespaces.rb', line 88

def initialize(parent = nil, attrs = [], prefix = nil, name = nil, markdown_odt_parser = nil)
  super parent, attrs, prefix, name
  @xml_parser = markdown_odt_parser
  style_index = attrs.index { |attr| attr.prefix == 'text' && attr.localname == 'style-name' }
  @enclosing_style = []
  if style_index and fetch_style?
    elem_style = find_style attrs[style_index].value
    fetch_style elem_style
  end
end