Implement many more nodes
All checks were successful
CI Pipeline / build (pull_request) Successful in 12s
All checks were successful
CI Pipeline / build (pull_request) Successful in 12s
Adds these new styling and formatting nodes * strike * highlight * linebreaks * pagebreaks * Hyperlinks
This commit is contained in:
@@ -37,6 +37,16 @@ module Notare
|
||||
render_list(xml, node)
|
||||
when Nodes::Table
|
||||
render_table(xml, node)
|
||||
when Nodes::Break
|
||||
render_page_break(xml, node)
|
||||
end
|
||||
end
|
||||
|
||||
def render_page_break(xml, _node)
|
||||
xml["w"].p do
|
||||
xml["w"].r do
|
||||
xml["w"].br("w:type" => "page")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -71,19 +81,42 @@ module Notare
|
||||
case run
|
||||
when Nodes::Image
|
||||
render_image(xml, run)
|
||||
when Nodes::Break
|
||||
render_break(xml, run)
|
||||
when Nodes::Hyperlink
|
||||
render_hyperlink(xml, run)
|
||||
when Nodes::Run
|
||||
render_text_run(xml, run)
|
||||
end
|
||||
end
|
||||
|
||||
def render_hyperlink(xml, hyperlink)
|
||||
xml["w"].hyperlink("r:id" => hyperlink.rid) do
|
||||
hyperlink.runs.each { |run| render_run(xml, run) }
|
||||
end
|
||||
end
|
||||
|
||||
def render_break(xml, break_node)
|
||||
xml["w"].r do
|
||||
if break_node.page?
|
||||
xml["w"].br("w:type" => "page")
|
||||
else
|
||||
xml["w"].br
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def render_text_run(xml, run)
|
||||
xml["w"].r do
|
||||
if run.bold || run.italic || run.underline || run.style
|
||||
if run.bold || run.italic || run.underline || run.strike || run.highlight || run.color || run.style
|
||||
xml["w"].rPr do
|
||||
xml["w"].rStyle("w:val" => run.style.style_id) if run.style
|
||||
xml["w"].b if run.bold
|
||||
xml["w"].i if run.italic
|
||||
xml["w"].u("w:val" => "single") if run.underline
|
||||
xml["w"].strike if run.strike
|
||||
xml["w"].highlight("w:val" => run.highlight) if run.highlight
|
||||
xml["w"].color("w:val" => run.color) if run.color
|
||||
end
|
||||
end
|
||||
xml["w"].t(run.text, "xml:space" => "preserve")
|
||||
|
||||
@@ -24,10 +24,12 @@ module Notare
|
||||
STYLES_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
|
||||
NUMBERING_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"
|
||||
IMAGE_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
|
||||
HYPERLINK_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
|
||||
|
||||
def initialize(has_numbering: false, images: [], has_styles: false)
|
||||
def initialize(has_numbering: false, images: [], hyperlinks: [], has_styles: false)
|
||||
@has_numbering = has_numbering
|
||||
@images = images
|
||||
@hyperlinks = hyperlinks
|
||||
@has_styles = has_styles
|
||||
end
|
||||
|
||||
@@ -60,6 +62,16 @@ module Notare
|
||||
Target: "media/#{image.filename}"
|
||||
)
|
||||
end
|
||||
|
||||
# Hyperlinks come after images
|
||||
@hyperlinks.each do |hyperlink|
|
||||
xml.Relationship(
|
||||
Id: hyperlink.rid,
|
||||
Type: HYPERLINK_TYPE,
|
||||
Target: hyperlink.url,
|
||||
TargetMode: "External"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
builder.to_xml
|
||||
|
||||
@@ -59,6 +59,8 @@ module Notare
|
||||
xml["w"].b if style.bold
|
||||
xml["w"].i if style.italic
|
||||
xml["w"].u("w:val" => "single") if style.underline
|
||||
xml["w"].strike if style.strike
|
||||
xml["w"].highlight("w:val" => style.highlight) if style.highlight
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user