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:
@@ -4,7 +4,7 @@ module Notare
|
||||
class Document
|
||||
include Builder
|
||||
|
||||
attr_reader :nodes, :styles
|
||||
attr_reader :nodes, :styles, :hyperlinks
|
||||
|
||||
def self.create(path, &block)
|
||||
doc = new
|
||||
@@ -21,7 +21,9 @@ module Notare
|
||||
@current_table = nil
|
||||
@current_row = nil
|
||||
@num_id_counter = 0
|
||||
@has_lists = false
|
||||
@images = {}
|
||||
@hyperlinks = []
|
||||
@styles = {}
|
||||
register_built_in_styles
|
||||
end
|
||||
@@ -42,10 +44,25 @@ module Notare
|
||||
@nodes.select { |n| n.is_a?(Nodes::List) }
|
||||
end
|
||||
|
||||
def uses_lists?
|
||||
@has_lists
|
||||
end
|
||||
|
||||
def mark_has_lists!
|
||||
@has_lists = true
|
||||
end
|
||||
|
||||
def images
|
||||
@images.values
|
||||
end
|
||||
|
||||
def register_hyperlink(url)
|
||||
rid = next_hyperlink_rid
|
||||
hyperlink = Nodes::Hyperlink.new(url: url, rid: rid)
|
||||
@hyperlinks << hyperlink
|
||||
hyperlink
|
||||
end
|
||||
|
||||
def register_image(path, width: nil, height: nil)
|
||||
return @images[path] if @images[path]
|
||||
|
||||
@@ -61,11 +78,17 @@ module Notare
|
||||
def next_image_rid
|
||||
# rId1 = styles.xml (always present)
|
||||
# rId2 = numbering.xml (if lists present)
|
||||
# rId3+ = images
|
||||
base = lists.any? ? 3 : 2
|
||||
# rId3+ = images, then hyperlinks
|
||||
base = @has_lists ? 3 : 2
|
||||
"rId#{base + @images.size}"
|
||||
end
|
||||
|
||||
def next_hyperlink_rid
|
||||
# Hyperlinks come after images
|
||||
base = @has_lists ? 3 : 2
|
||||
"rId#{base + @images.size + @hyperlinks.size}"
|
||||
end
|
||||
|
||||
def register_built_in_styles
|
||||
# Headings (spacing_before ensures they're rendered as paragraph styles)
|
||||
define_style :heading1, size: 24, bold: true, spacing_before: 240, spacing_after: 120
|
||||
|
||||
Reference in New Issue
Block a user