Module: IsoDoc::WordFunction::Comments
- Included in:
- IsoDoc::WordConvert
- Defined in:
- lib/isodoc/word_function/comments.rb
Constant Summary collapse
- COMMENT_IN_COMMENT_LIST1 =
'//div[@style="mso-element:comment-list"]//'\ 'span[@style="MsoCommentReference"]'.freeze
- COMMENT_TARGET_XREFS1 =
"//span[@style='mso-special-character:comment']/@target".freeze
Instance Method Summary collapse
- #comment_attributes(docxml, x) ⇒ Object
- #comment_cleanup(docxml) ⇒ Object
- #comment_link_attrs(fn, node) ⇒ Object
- #comments(div) ⇒ Object
- #embed_comment_in_comment_list(docxml) ⇒ Object
- #get_comments_from_text(docxml, link_order) ⇒ Object
- #in_comment ⇒ Object
- #insert_comment_cont(from, to, target) ⇒ Object
-
#make_comment_link(out, fn, node) ⇒ Object
add in from and to links to move the comment into place.
- #make_comment_target(out) ⇒ Object
- #make_comment_text(node, fn) ⇒ Object
- #move_comment_link_to_from(docxml) ⇒ Object
- #move_comment_link_to_from1(x, fromlink) ⇒ Object
- #reorder_comments_by_comment_link(docxml) ⇒ Object
- #review_note_parse(node, out) ⇒ Object
- #skip_comment_wrap(from) ⇒ Object
- #wrap_comment_cont(from, target) ⇒ Object
Instance Method Details
#comment_attributes(docxml, x) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/isodoc/word_function/comments.rb', line 85 def comment_attributes(docxml, x) fromlink = docxml.at("//*[@id='#{x['from']}']") return(nil) if fromlink.nil? tolink = docxml.at("//*[@id='#{x['to']}']") || fromlink target = docxml.at("//*[@id='#{x['target']}']") { from: fromlink, to: tolink, target: target } end |
#comment_cleanup(docxml) ⇒ Object
59 60 61 62 63 |
# File 'lib/isodoc/word_function/comments.rb', line 59 def comment_cleanup(docxml) move_comment_link_to_from(docxml) reorder_comments_by_comment_link(docxml) (docxml) end |
#comment_link_attrs(fn, node) ⇒ Object
23 24 25 26 27 |
# File 'lib/isodoc/word_function/comments.rb', line 23 def comment_link_attrs(fn, node) { style: "MsoCommentReference", target: fn, class: "commentLink", from: node["from"], to: node["to"] } end |
#comments(div) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/isodoc/word_function/comments.rb', line 8 def comments(div) return if @comments.empty? div.div **{ style: "mso-element:comment-list" } do |div1| @comments.each { |fn| div1.parent << fn } end end |
#embed_comment_in_comment_list(docxml) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/isodoc/word_function/comments.rb', line 69 def (docxml) #docxml.xpath(COMMENT_IN_COMMENT_LIST).each do |x| docxml.xpath(COMMENT_IN_COMMENT_LIST1).each do |x| n = x.next_element n&.children&.first&.add_previous_sibling(x.remove) end docxml end |
#get_comments_from_text(docxml, link_order) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/isodoc/word_function/comments.rb', line 122 def get_comments_from_text(docxml, link_order) comments = [] docxml.xpath("//div[@style='mso-element:comment']").each do |c| next unless c["id"] && !link_order[c["id"]].nil? comments << { text: c.remove.to_s, id: c["id"] } end comments.sort! { |a, b| link_order[a[:id]] <=> link_order[b[:id]] } # comments end |
#in_comment ⇒ Object
4 5 6 |
# File 'lib/isodoc/word_function/comments.rb', line 4 def in_comment @in_comment end |
#insert_comment_cont(from, to, target) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/isodoc/word_function/comments.rb', line 102 def insert_comment_cont(from, to, target) # includes_to = from.at(".//*[@id='#{to}']") while !from.nil? && from["id"] != to following = from.xpath("./following::*") (from = following.shift) && incl_to = from.at(".//*[@id='#{to}']") while !incl_to.nil? && !from.nil? && skip_comment_wrap(from) (from = following.shift) && incl_to = from.at(".//*[@id='#{to}']") end wrap_comment_cont(from, target) if !from.nil? end end |
#make_comment_link(out, fn, node) ⇒ Object
add in from and to links to move the comment into place
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/isodoc/word_function/comments.rb', line 30 def make_comment_link(out, fn, node) out.span(**comment_link_attrs(fn, node)) do |s1| s1.span **{ lang: "EN-GB", style: "font-size:9.0pt" } do |s2| s2.a **{ style: "mso-comment-reference:SMC_#{fn};"\ "mso-comment-date:#{node['date'].gsub(/[:-]+/, '')}" } s2.span **{ style: "mso-special-character:comment", target: fn } # do |s| end end end |
#make_comment_target(out) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/isodoc/word_function/comments.rb', line 41 def make_comment_target(out) out.span **{ style: "MsoCommentReference" } do |s1| s1.span **{ lang: "EN-GB", style: "font-size:9.0pt" } do |s2| s2.span **{ style: "mso-special-character:comment" } end end end |
#make_comment_text(node, fn) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/isodoc/word_function/comments.rb', line 49 def make_comment_text(node, fn) noko do |xml| xml.div **{ style: "mso-element:comment", id: fn } do |div| div.span **{ style: %{mso-comment-author:"#{node['reviewer']}"} } make_comment_target(div) node.children.each { |n| parse(n, div) } end end.join("\n") end |
#move_comment_link_to_from(docxml) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/isodoc/word_function/comments.rb', line 114 def move_comment_link_to_from(docxml) docxml.xpath('//span[@style="MsoCommentReference"][@from]').each do |x| attrs = comment_attributes(docxml, x) || next move_comment_link_to_from1(x, attrs[:from]) insert_comment_cont(attrs[:from], x["to"], x["target"]) end end |
#move_comment_link_to_from1(x, fromlink) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/isodoc/word_function/comments.rb', line 78 def move_comment_link_to_from1(x, fromlink) x.remove link = x.at(".//a") fromlink.replace(x) link.children = fromlink end |
#reorder_comments_by_comment_link(docxml) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/isodoc/word_function/comments.rb', line 135 def reorder_comments_by_comment_link(docxml) link_order = {} docxml.xpath(COMMENT_TARGET_XREFS1).each_with_index do |target, i| link_order[target.value] = i end comments = get_comments_from_text(docxml, link_order) list = docxml.at("//*[@style='mso-element:comment-list']") || return list.children = comments.map { |c| c[:text] }.join("\n") end |
#review_note_parse(node, out) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/isodoc/word_function/comments.rb', line 15 def review_note_parse(node, out) fn = @comments.length + 1 make_comment_link(out, fn, node) @in_comment = true @comments << make_comment_text(node, fn) @in_comment = false end |
#skip_comment_wrap(from) ⇒ Object
98 99 100 |
# File 'lib/isodoc/word_function/comments.rb', line 98 def skip_comment_wrap(from) from["style"] != "mso-special-character:comment" end |
#wrap_comment_cont(from, target) ⇒ Object
93 94 95 96 |
# File 'lib/isodoc/word_function/comments.rb', line 93 def wrap_comment_cont(from, target) s = from.replace("<span style='mso-comment-continuation:#{target}'>") s.first.children = from end |