Skip to content

Commit

Permalink
Merge pull request #180 from metanorma/fix/definition-spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis authored Nov 22, 2022
2 parents abcb43d + cc2d666 commit 2dcc368
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

.rubocop-https--*

/Gemfile.devel
/Gemfile.lock
/test.err
/test.rfc.xml.err
1 change: 1 addition & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "main"
10 changes: 5 additions & 5 deletions lib/isodoc/ietf/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def make_postamble(docxml)
c = a&.xpath("./following-sibling::*")&.remove
a = a.remove
name and f << name
b.empty? or f << "<preamble>#{b.to_xml}</preamble>"
b.empty? or f << "<preamble>#{to_xml(b)}</preamble>"
a and f << a
c.empty? or f << "<postamble>#{c.to_xml}</postamble>"
c.empty? or f << "<postamble>#{to_xml(c)}</postamble>"
end
end

Expand All @@ -127,11 +127,11 @@ def move_preamble(docxml)
# for markup in pseudocode
def sourcecode_cleanup(docxml)
docxml.xpath("//sourcecode").each do |s|
s.children = s.children.to_xml.gsub(%r{<br/>\n}, "\n")
s.children = to_xml(s.children).gsub(%r{<br/>\n}, "\n")
.gsub(%r{\s+(<t[ >])}, "\\1").gsub(%r{</t>\s+}, "</t>")
sourcecode_remove_markup(s)
s.children = "<![CDATA[#{HTMLEntities.new.decode(s
.children.to_xml.sub(/\A\n+/, ''))}]]>"
s.children = "<![CDATA[#{HTMLEntities.new.decode(to_xml(s
.children).sub(/\A\n+/, ''))}]]>"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/ietf/cleanup_inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def u_cleanup(xmldoc)
def footnote_cleanup(docxml)
fn = footnote_refs_cleanup(docxml)
endnotes = make_endnotes(docxml)
docxml.xpath("//section[descendant::fn] | "\
docxml.xpath("//section[descendant::fn] | " \
"//abstract[descendant::fn]").each do |s|
s.xpath(".//fn").each do |f|
ref = f.at(".//ref") and ref.replace("[#{fn[ref.text]}] ")
Expand Down
18 changes: 11 additions & 7 deletions lib/isodoc/ietf/footnotes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ module IsoDoc::Ietf
class RfcConvert < ::IsoDoc::Convert
def footnote_parse(node, out)
return table_footnote_parse(node, out) if @in_table || @in_figure

fn = node["reference"]
out.fnref fn
make_local_footnote(node, fn, out)
end

def make_local_footnote(node, fn, out)
return if @seen_footnote.include?(fn)

@in_footnote = true
out << make_generic_footnote_text(node, fn)
@in_footnote = false
Expand All @@ -18,13 +20,13 @@ def make_local_footnote(node, fn, out)
def make_generic_footnote_text(node, fnref)
first = node.first_element_child
noko do |xml|
xml.fn do |div|
xml.fn do |_div|
xml.t **attr_code(anchor: first ? first["id"] : nil) do |div|
div.ref fnref
first.name == "p" and first.children.each { |n| parse(n, div) }
end
first.name == "p" and
node.elements.drop(1).each { |n| parse(n, xml) } or
(first.name == "p" and
node.elements.drop(1).each { |n| parse(n, xml) }) or
node.children.each { |n| parse(n, xml) }
end
end.join
Expand All @@ -36,6 +38,7 @@ def table_footnote_parse(node, out)
make_table_footnote_link(out, tid + fn, fn)
# do not output footnote text if we have already seen it for this table
return if @seen_footnote.include?(tid + fn)

@in_footnote = true
out.fn do |a|
a << make_table_footnote_text(node, tid + fn, fn)
Expand All @@ -44,26 +47,27 @@ def table_footnote_parse(node, out)
@seen_footnote << (tid + fn)
end

def make_table_footnote_link(out, fnid, fnref)
def make_table_footnote_link(out, _fnid, fnref)
out << " [#{fnref}]"
end

def make_table_footnote_text(node, fnid, fnref)
def make_table_footnote_text(node, _fnid, fnref)
first = node.first_element_child
noko do |xml|
xml.t **attr_code(anchor: first ? first["id"] : nil) do |div|
div << "[#{fnref}] "
first.name == "p" and first.children.each { |n| parse(n, div) }
end
first.name == "p" and
node.elements.drop(1).each { |n| parse(n, xml) } or
(first.name == "p" and
node.elements.drop(1).each { |n| parse(n, xml) }) or
node.children.each { |n| parse(n, xml) }
end.join
end

def get_table_ancestor_id(node)
table = node.ancestors("table") || node.ancestors("figure")
return UUIDTools::UUID.random_create.to_s if table.empty?

table.last["id"]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/ietf/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_linkend(node)
end
contents = no_loc_contents.select { |c| !c.text? || /\S/.match(c) }
!contents.empty? and
return Nokogiri::XML::NodeSet.new(node.document, contents).to_xml
return to_xml(Nokogiri::XML::NodeSet.new(node.document, contents))
""
end

Expand Down

0 comments on commit 2dcc368

Please sign in to comment.