Skip to content

Commit

Permalink
Merge pull request #93 from metanorma/fix/clause-list-style
Browse files Browse the repository at this point in the history
bring list and clause numbering in line with ISO: https://github.com/…
  • Loading branch information
opoudjis authored Aug 15, 2024
2 parents 54f4c43 + b84c3ce commit 4571da7
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 242 deletions.
1 change: 1 addition & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem "metanorma-jis", git: "https://github.com/metanorma/metanorma-jis", branch: "main"
13 changes: 13 additions & 0 deletions lib/isodoc/plateau/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
module IsoDoc
module Plateau
class PresentationXMLConvert < IsoDoc::JIS::PresentationXMLConvert
def initialize(options)
@iso = ::IsoDoc::Iso::PresentationXMLConvert.new(options)
super
end

def toc_title_insert_pt(docxml)
i = preface_init_insert_pt(docxml) or return nil
a = i.at(ns("./abstract[last()] | ./clause[@type = 'revhistory']")) and
Expand Down Expand Up @@ -70,6 +75,14 @@ def commentary_title_hdr(elem)
elem.previous = ret
end

def ol_depth(node)
@iso.ol_depth(node)
end

def bibliography_bibitem_number(docxml)
super
end

include Init
end
end
Expand Down
49 changes: 13 additions & 36 deletions lib/isodoc/plateau/xref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ class Counter < IsoDoc::XrefGen::Counter
end

class Xref < IsoDoc::JIS::Xref
def initialize(lang, script, klass, i18n, options)
@iso = ::IsoDoc::Iso::Xref.new(lang, script, klass, i18n, options)
super
end

def clause_order_main(_docxml)
[
{
Expand Down Expand Up @@ -39,42 +44,6 @@ def middle_asset_names(clause, container: false)
end
end

def section_name_anchors(clause, num, level)
super
if level >= 4 && level <= 6
label, xref = section_name_anchors_deep(num, level)
@anchors[clause["id"]][:label] = label
@anchors[clause["id"]][:xref] = l10n(xref)
end
end

def section_name_anchors_deep(num, level)
numparts = num.split(".")
core = numparts[0..2].join(".")
(4..level).each do |l|
core += " #{section_name_label_deep(numparts[l - 1], l)}"
end
[section_name_label_deep(numparts[-1], level), l10n(core)]
end

def section_name_label_deep(num, level)
case level
when 4 then l10n("(#{num})")
when 5 then l10n("#{num})")
when 6
("" << (num.to_i + 0x245f))
end
end

def annex_name_anchors1(clause, num, level)
super
if level >= 4 && level <= 6
label, xref = section_name_anchors_deep(num, level)
@anchors[clause["id"]][:label] = label
@anchors[clause["id"]][:xref] = l10n(xref)
end
end

def hierarchical_figure_names(clause, num)
c = IsoDoc::XrefGen::Counter.new
j = 0
Expand Down Expand Up @@ -102,6 +71,14 @@ def hierarchical_figure_class_names(clause, num)
end
end

def list_item_anchor_names(list, list_anchor, depth, prev_label,
refer_list)
@iso.list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list)
end

def list_item_value(entry, counter, depth, opts)
@iso.list_item_value(entry, counter, depth, opts)
end
end
end
end
19 changes: 13 additions & 6 deletions lib/metanorma/plateau/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ def blocksource_cleanup(xmldoc)
super
end

def pub_class(bib)
return 1 if bib.at("#{PUBLISHER}[name = '#{pub_hash['en']}']") ||
bib.at("#{PUBLISHER}[name = '#{pub_hash['ja']}']") ||
bib.at("#{PUBLISHER}[abbreviation = 'MLIT']")
return 2 if bib["type"] == "standard"
# Abandoned in favour of JIS ordering
# def pub_class(bib)
# return 1 if bib.at("#{PUBLISHER}[name = '#{pub_hash['en']}']") ||
# bib.at("#{PUBLISHER}[name = '#{pub_hash['ja']}']") ||
# bib.at("#{PUBLISHER}[abbreviation = 'MLIT']")
# return 2 if bib["type"] == "standard"
#
# 3
# end

3
def biblio_reorder(xmldoc)
xmldoc.xpath("//references").each do |r|
biblio_reorder1(r)
end
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/isodoc/blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@
<origin bibitemid="x" type="inline" citeas="Clause 1">4</origin>
]
</p>
<ol id="_" type="alphabetic">
<li id="_" label="a">
<ol id="_" type="alphabet">
<li id="_" label="">
<p id="_">List</p>
</li>
</ol>
Expand Down Expand Up @@ -486,7 +486,7 @@
]
</p>
<div class="ol_wrap">
<ol id="_">
<ol type="a" id="_" class="alphabet">
<li id="_">
<p id="_">List</p>
</li>
Expand Down
204 changes: 102 additions & 102 deletions spec/isodoc/sections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,129 +609,129 @@
</iso-standard>
INPUT
presxml = <<~OUTPUT
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<preface>
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<preface>
<clause type="toc" id="_" displayorder="1">
<title depth="1">Contents</title>
<title depth="1">Contents</title>
</clause>
</preface>
<sections>
</preface>
<sections>
<clause id="S1" obligation="normative" displayorder="2">
<title depth="1">
1
<tab/>
Scope
</title>
<clause id="S2" obligation="normative">
<title depth="2">
1.1
<title depth="1">
1
<tab/>
Scope
</title>
<clause id="S3" obligation="normative">
<title depth="3">
1.1.1
<tab/>
Scope
</title>
<clause id="S2" obligation="normative">
<title depth="2">
1.1
<tab/>
Scope
</title>
<clause id="S4" obligation="normative">
<title depth="4">
(1)
<tab/>
Scope
</title>
<clause id="S5" obligation="normative">
<title depth="5">
1)
<clause id="S3" obligation="normative">
<title depth="3">
1.1.1
<tab/>
Scope
</title>
<clause id="S6a" obligation="normative">
<title depth="6">
<tab/>
Scope
</title>
</clause>
<clause id="S6b" obligation="normative">
<title depth="6">
<tab/>
Scope
</title>
<clause id="S4" obligation="normative">
<title depth="4">
1.1.1.1
<tab/>
Scope
</title>
</clause>
<clause id="S6c" obligation="normative">
<title depth="6">
<tab/>
Scope
</title>
</clause>
</clause>
<clause id="S5" obligation="normative">
<title depth="5">
1.1.1.1.1
<tab/>
Scope
</title>
<clause id="S6a" obligation="normative">
<title depth="6">
1.1.1.1.1.1
<tab/>
Scope
</title>
</clause>
<clause id="S6b" obligation="normative">
<title depth="6">
1.1.1.1.1.2
<tab/>
Scope
</title>
</clause>
<clause id="S6c" obligation="normative">
<title depth="6">
1.1.1.1.1.3
<tab/>
Scope
</title>
</clause>
</clause>
</clause>
</clause>
</clause>
</clause>
</clause>
</clause>
</sections>
<annex id="P" inline-header="false" obligation="normative" displayorder="3">
</sections>
<annex id="P" inline-header="false" obligation="normative" displayorder="3">
<title>
Annex A
<br/>
(normative)
<br/>
<strong>Annex</strong>
Annex A
<br/>
(normative)
<br/>
<strong>Annex</strong>
</title>
<clause id="A1" obligation="normative">
<title depth="2">
A.1
<tab/>
Scope
</title>
<clause id="A2" obligation="normative">
<title depth="3">
A.1.1
<title depth="2">
A.1
<tab/>
Scope
</title>
<clause id="A3" obligation="normative">
<title depth="4">
(1)
<tab/>
Scope
</title>
<clause id="A2" obligation="normative">
<title depth="3">
A.1.1
<tab/>
Scope
</title>
<clause id="A4" obligation="normative">
<title depth="5">
1)
<tab/>
Scope
</title>
<clause id="A6a" obligation="normative">
<title depth="6">
<clause id="A3" obligation="normative">
<title depth="4">
A.1.1.1
<tab/>
Scope
</title>
</clause>
<clause id="A6b" obligation="normative">
<title depth="6">
<tab/>
Scope
</title>
</clause>
<clause id="A6c" obligation="normative">
<title depth="6">
<tab/>
Scope
</title>
</clause>
</title>
<clause id="A4" obligation="normative">
<title depth="5">
A.1.1.1.1
<tab/>
Scope
</title>
<clause id="A6a" obligation="normative">
<title depth="6">
A.1.1.1.1.1
<tab/>
Scope
</title>
</clause>
<clause id="A6b" obligation="normative">
<title depth="6">
A.1.1.1.1.2
<tab/>
Scope
</title>
</clause>
<clause id="A6c" obligation="normative">
<title depth="6">
A.1.1.1.1.3
<tab/>
Scope
</title>
</clause>
</clause>
</clause>
</clause>
</clause>
</clause>
</clause>
</annex>
</iso-standard>
</annex>
</iso-standard>
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::Plateau::PresentationXMLConvert
.new(presxml_options)
Expand Down
Loading

0 comments on commit 4571da7

Please sign in to comment.