Permalink
Browse files

parses h1, h2 and underline

  • Loading branch information...
1 parent b851d3a commit 525135af21624d0fbe9a4e861a6bc9b3f32f14ae @sandrods committed Jan 15, 2013
Showing with 12 additions and 6 deletions.
  1. +12 −6 lib/odf-report/parser/default.rb
@@ -36,10 +36,10 @@ def initialize(text, template_node)
def parse
xml = @template_node.parse(@text)
- xml.css("p").each do |p|
+ xml.css("p", "h1", "h2").each do |p|
- style = check_ident(p)
- text = parse_styles(p.inner_html)
+ style = check_style(p)
+ text = parse_formatting(p.inner_html)
add_paragraph(text, style)
end
@@ -57,21 +57,27 @@ def add_paragraph(text, style)
private
- def parse_styles(text)
+ def parse_formatting(text)
text.strip!
text.gsub!(/<strong>(.+)<\/strong>/) { "<text:span text:style-name=\"bold\">#{$1}<\/text:span>" }
text.gsub!(/<em>(.+)<\/em>/) { "<text:span text:style-name=\"italic\">#{$1}<\/text:span>" }
+ text.gsub!(/<u>(.+)<\/u>/) { "<text:span text:style-name=\"underline\">#{$1}<\/text:span>" }
text.gsub!("\n", "")
text
end
- def check_ident(node)
+ def check_style(node)
style = nil
- if node.parent && node.parent.name == "blockquote"
+ if node.name =~ /h\d/i
+ style = "title"
+
+ elsif node.parent && node.parent.name == "blockquote"
style = "quote"
+
elsif node['style'] =~ /margin/
style = "quote"
+
end
style

0 comments on commit 525135a

Please sign in to comment.