Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xref of bookmarks: https://github.com/metanorma/metanorma-bipm/issues/67 #236

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/isodoc/xref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def parse(docxml)
note_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
example_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
list_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
bookmark_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
end

def ns(xpath)
Expand Down
14 changes: 14 additions & 0 deletions lib/isodoc/xref/xref_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,19 @@ def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list)
end
end
end

def bookmark_anchor_names(sections)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment Branch Condition size for bookmark_anchor_names is too high. [21.19/15]
Method has too many lines. [11/10]

sections.each do |s|
notes = s.xpath(ns(".//bookmark")) - s.xpath(ns(".//clause//bookmark")) -
s.xpath(ns(".//appendix//bookmark"))
notes.each do |n|
next if n["id"].nil? || n["id"].empty?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty line after guard clause.
Use n["id"].blank? instead of n["id"].nil? || n["id"].empty?.

@anchors[n["id"]] = {
type: "bookmark", label: nil, value: nil,
xref: @anchors[s["id"]][:xref] }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing hash brace must be on the line after the last hash element when opening brace is on a separate line from the first hash element.

end
bookmark_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
end
end
end
end
145 changes: 145 additions & 0 deletions spec/isodoc/xref_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,151 @@
OUTPUT
end

it "cross-references bookmarks" do
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}).convert("test", <<~"INPUT", true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not 4) spaces for indentation.
Line is too long. [130/120]

<iso-standard xmlns="http://riboseinc.com/isoxml">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 spaces for indentation in a heredoc.

<preface>
<foreword>
<p>
<xref target="N1"/>
<xref target="N2"/>
<xref target="N"/>
<xref target="note1"/>
<xref target="note2"/>
<xref target="AN"/>
<xref target="Anote1"/>
<xref target="Anote2"/>
</p>
</foreword>
<introduction id="intro">
<p id="N01">
<bookmark id="N1"/>
</p>
<clause id="xyz"><title>Preparatory</title>
<p id="N02" type="arabic">
<bookmark id="N2"/>
</p>
</clause>
</introduction>
</preface>
<sections>
<clause id="scope" type="scope"><title>Scope</title>
<p id="N0" type="roman">
<bookmark id="N"/>
</p>
</clause>
<terms id="terms"/>
<clause id="widgets"><title>Widgets</title>
<clause id="widgets1">
<p id="note1l" type="alphabet">
<bookmark id="note1"/>
</p>
<p id="note2l" type="roman_upper">
<bookmark id="note2"/>
</p>
</clause>
</clause>
</sections>
<annex id="annex1">
<clause id="annex1a">
<p id="ANl" type="alphabet_upper">
<bookmark id="AN"/>
</p>
</clause>
<clause id="annex1b">
<p id="Anote1l" type="roman" start="4">
<bookmark id="Anote1"/>
</p>
<p id="Anote2l">
<bookmark id="Anote2"/>
</p>
</clause>
</annex>
</iso-standard>
INPUT
<iso-standard xmlns='http://riboseinc.com/isoxml' type='presentation'>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 spaces for indentation in a heredoc.

<preface>
<foreword>
<p>
<xref target='N1'>Introduction</xref>
<xref target='N2'>Preparatory</xref>
<xref target='N'>Clause 1</xref>
<xref target='note1'>Clause 3.1</xref>
<xref target='note2'>Clause 3.1</xref>
<xref target='AN'>Annex A.1</xref>
<xref target='Anote1'>Annex A.2</xref>
<xref target='Anote2'>Annex A.2</xref>
</p>
</foreword>
<introduction id='intro'>
<p id='N01'>
<bookmark id='N1'/>
</p>
<clause id='xyz'>
<title depth='2'>Preparatory</title>
<p id='N02' type='arabic'>
<bookmark id='N2'/>
</p>
</clause>
</introduction>
</preface>
<sections>
<clause id='scope' type='scope'>
<title depth='1'>
1.
<tab/>
Scope
</title>
<p id='N0' type='roman'>
<bookmark id='N'/>
</p>
</clause>
<terms id='terms'>
<title>2.</title>
</terms>
<clause id='widgets'>
<title depth='1'>
3.
<tab/>
Widgets
</title>
<clause id='widgets1'>
<title>3.1.</title>
<p id='note1l' type='alphabet'>
<bookmark id='note1'/>
</p>
<p id='note2l' type='roman_upper'>
<bookmark id='note2'/>
</p>
</clause>
</clause>
</sections>
<annex id='annex1'>
<title>
<strong>Annex A</strong>
<br/>
(informative)
</title>
<clause id='annex1a'>
<title>A.1.</title>
<p id='ANl' type='alphabet_upper'>
<bookmark id='AN'/>
</p>
</clause>
<clause id='annex1b'>
<title>A.2.</title>
<p id='Anote1l' type='roman' start='4'>
<bookmark id='Anote1'/>
</p>
<p id='Anote2l'>
<bookmark id='Anote2'/>
</p>
</clause>
</annex>
</iso-standard>
OUTPUT
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OUTPUT is not aligned with expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}).convert("test", <<"INPUT", true))).to be_equivalent_to xmlpp(<<"OUTPUT") or beginning of method definition.

end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 2693, 0 is not aligned with it "cross-references bookmarks" do at 2550, 2.


it "realises subsequences" do
expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}).convert("test", <<~"INPUT", true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
<iso-standard xmlns="http://riboseinc.com/isoxml">
Expand Down