-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #594 from metanorma/fix/defensive_add_first_child
Fix/defensive add first child
- Loading branch information
Showing
12 changed files
with
99 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,64 @@ | ||
module IsoDoc::HtmlFunction | ||
module Html | ||
def update_footnote_filter(fn, x, i, seen) | ||
if seen[fn.text] | ||
x.at("./sup").content = seen[fn.text][:num].to_s | ||
fn.remove unless x["href"] == seen[fn.text][:href] | ||
x["href"] = seen[fn.text][:href] | ||
else | ||
seen[fn.text] = { num: i, href: x["href"] } | ||
x.at("./sup").content = i.to_s | ||
i += 1 | ||
module IsoDoc | ||
module HtmlFunction | ||
module Html | ||
def update_footnote_filter(fnote, xref, idx, seen) | ||
if seen[fnote.text] | ||
xref.at("./sup").content = seen[fnote.text][:num].to_s | ||
fnote.remove unless xref["href"] == seen[fnote.text][:href] | ||
xref["href"] = seen[fnote.text][:href] | ||
else | ||
seen[fnote.text] = { num: idx, href: xref["href"] } | ||
xref.at("./sup").content = idx.to_s | ||
idx += 1 | ||
end | ||
[idx, seen] | ||
end | ||
[i, seen] | ||
end | ||
|
||
def html_footnote_filter(docxml) | ||
seen = {} | ||
i = 1 | ||
docxml.xpath('//a[@class = "FootnoteRef"]').each do |x| | ||
fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next | ||
i, seen = update_footnote_filter(fn, x, i, seen) | ||
def html_footnote_filter(docxml) | ||
seen = {} | ||
i = 1 | ||
docxml.xpath('//a[@class = "FootnoteRef"]').each do |x| | ||
fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next | ||
i, seen = update_footnote_filter(fn, x, i, seen) | ||
end | ||
docxml | ||
end | ||
docxml | ||
end | ||
|
||
def footnote_backlinks1(x, fn) | ||
xdup = x.dup | ||
xdup.remove["id"] | ||
if fn.elements.empty? | ||
fn.children.first.previous = xdup | ||
else | ||
fn.elements.first.children.first.previous = xdup | ||
def footnote_backlinks1(xref, footnote) | ||
xdup = xref.dup | ||
xdup.remove["id"] | ||
if footnote.elements.empty? | ||
#footnote.children.empty? and footnote << " " | ||
#footnote.children.first.previous = xdup | ||
footnote.add_first_child xdup | ||
else | ||
#footnote.elements.first.children.first.previous = xdup | ||
footnote.elements.first.add_first_child xdup | ||
end | ||
end | ||
end | ||
|
||
def footnote_backlinks(docxml) | ||
seen = {} | ||
docxml.xpath('//a[@class = "FootnoteRef"]').each_with_index do |x, i| | ||
(seen[x["href"]] and next) or seen[x["href"]] = true | ||
fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next | ||
footnote_backlinks1(x, fn) | ||
x["id"] ||= "fnref:#{i + 1}" | ||
fn.add_child "<a href='##{x['id']}'>↩</a>" | ||
def footnote_backlinks(docxml) | ||
seen = {} | ||
docxml.xpath('//a[@class = "FootnoteRef"]').each_with_index do |x, i| | ||
(seen[x["href"]] and next) or seen[x["href"]] = true | ||
fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next | ||
footnote_backlinks1(x, fn) | ||
x["id"] ||= "fnref:#{i + 1}" | ||
fn.add_child "<a href='##{x['id']}'>↩</a>" | ||
end | ||
docxml | ||
end | ||
docxml | ||
end | ||
|
||
def footnote_format(docxml) | ||
docxml.xpath("//a[@class = 'FootnoteRef']/sup").each do |x| | ||
footnote_reference_format(x) | ||
end | ||
docxml.xpath("//a[@class = 'TableFootnoteRef'] | "\ | ||
"//span[@class = 'TableFootnoteRef']").each do |x| | ||
table_footnote_reference_format(x) | ||
def footnote_format(docxml) | ||
docxml.xpath("//a[@class = 'FootnoteRef']/sup").each do |x| | ||
footnote_reference_format(x) | ||
end | ||
docxml.xpath("//a[@class = 'TableFootnoteRef'] | "\ | ||
"//span[@class = 'TableFootnoteRef']").each do |x| | ||
table_footnote_reference_format(x) | ||
end | ||
docxml | ||
end | ||
docxml | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Nokogiri | ||
module XML | ||
class Node | ||
def add_first_child(content) | ||
if children.empty? | ||
add_child(content) | ||
else | ||
children.first.previous = content | ||
end | ||
end | ||
end | ||
end | ||
end |