Skip to content

Commit

Permalink
Debug insertion of <u> for unicode characters, was passing through &l…
Browse files Browse the repository at this point in the history
…t; as decoded <: #216
  • Loading branch information
opoudjis committed Dec 5, 2024
1 parent 5e419d4 commit 5894ec4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
10 changes: 5 additions & 5 deletions lib/isodoc/ietf/cleanup_inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module Ietf
class RfcConvert < ::IsoDoc::Convert
def u_cleanup(xmldoc)
xmldoc.traverse do |n|
next unless n.text?
next unless %w(t blockquote li dd preamble td th annotation)
.include? n.parent.name

n.replace(n.text.gsub(/[\u0080-\uffff]/, "<u>\\0</u>"))
n.text? or next
%w(t blockquote li dd preamble td th annotation)
.include? n.parent.name or next
n.replace(@c.encode(n.text, :basic).gsub(/[\u0080-\uffff]/,
"<u>\\0</u>"))
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/ietf/isodoc.rng
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
these elements; we just want one namespace for any child grammars
of this.
-->
<!-- VERSION v1.4.0 -->
<!-- VERSION v1.4.1 -->
<grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<include href="reqt.rng"/>
<include href="basicdoc.rng">
Expand Down
11 changes: 6 additions & 5 deletions spec/isodoc/cleanup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,8 @@
<rfc xmlns:xi='http://www.w3.org/2001/XInclude' version='3'>
<front>
<abstract>
<author>Hello Χello</author>
<t>Hello Χello</t>
<author>Hello &lt;"Χello</author>
<t>Hello &lt;"Χello</t>
</abstract>
</front>
<middle/>
Expand All @@ -959,17 +959,18 @@
<front>
<abstract>
<author>
Hello &#x3A7;ello
Hello &lt;"&#x3A7;ello
</author>
<t>
Hello
<u>&#x3A7;</u>
&lt;"<u>&#x3A7;</u>
ello
</t>
</abstract> </front> <middle/> <back/> </rfc>
OUTPUT
expect(Xml::C14n.format(IsoDoc::Ietf::RfcConvert.new({})
.cleanup(Nokogiri::XML(input)).to_s)).to be_equivalent_to Xml::C14n.format(output)
.cleanup(Nokogiri::XML(input)).to_s))
.to be_equivalent_to Xml::C14n.format(output)
end

it "cleans up lists with single paragraphs" do
Expand Down
40 changes: 34 additions & 6 deletions spec/isodoc/inline_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
require "spec_helper"

RSpec.describe IsoDoc::Ietf::RfcConvert do
it "respect &lt; &gt;" do
FileUtils.rm_f "test.rfc.xml"
input = <<~INPUT
#{BLANK_HDR}
<preface><foreword>
<p>&lt;pizza&gt;</p>
</foreword></preface>
<sections>
</iso-standard>
INPUT
IsoDoc::Ietf::RfcConvert.new({})
.convert("test", input, false)
expect(Xml::C14n.format(File.read("test.rfc.xml")))
.to be_equivalent_to Xml::C14n.format(<<~OUTPUT)
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" category="std" ipr="trust200902" submissionType="IETF" xml:lang="en" version="3">
<front>
<title>Document title</title>
<seriesInfo value="" status="Published" stream="IETF" name="Internet-Draft" asciiName="Internet-Draft"/>
<abstract>
<t>&lt;pizza&gt;</t>
</abstract>
</front>
<middle/>
<back/>
</rfc>
OUTPUT
end

it "processes inline formatting" do
input = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
Expand Down Expand Up @@ -708,26 +736,26 @@
<em>word</em>
[term defined in
<xref target="ISO712" section="3.1, Figure a" relative="">
</xref>
]
</li>
<li>
<em>word</em>
[term defined in
<xref target="ISO712" section="3.1 and Figure b" relative="">
</xref>
]
</li>
<li>
<em>word</em>
[term defined in
<xref target="ISO712" section="3.1 and Figure b" relative="">
The Aforementioned Citation
</xref>
]
Expand Down

0 comments on commit 5894ec4

Please sign in to comment.