Skip to content

Commit

Permalink
allow duplicate designations; severities on log messages: metanorma/m…
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Dec 7, 2023
1 parent b9c5243 commit aca3178
Show file tree
Hide file tree
Showing 37 changed files with 817 additions and 922 deletions.
5 changes: 2 additions & 3 deletions lib/metanorma/standoc/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Base
XML_NAMESPACE = "https://www.metanorma.org/ns/standoc".freeze
FONTS_MANIFEST = "fonts-manifest".freeze

attr_accessor :log, :fatalerror
attr_accessor :log

def xml_root_tag
self.class::XML_ROOT_TAG
Expand Down Expand Up @@ -110,7 +110,6 @@ def init_output(node)
end
@localdir = Metanorma::Utils::localdir(node)
@output_dir = outputdir node
@fatalerror = []
end

def init_i18n(node)
Expand Down Expand Up @@ -141,7 +140,7 @@ def document(node)
clean_exit
ret
rescue StandardError => e
@log.add("Fatal Error", nil, e.message)
@log.add("Fatal Error", nil, e.message, severity: 0)
clean_exit
raise e
end
Expand Down
8 changes: 5 additions & 3 deletions lib/metanorma/standoc/cleanup_asciibib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def validate_ref_dl(bib, clause)
unless id
@log.add("Anchors", clause,
"The following reference is missing an anchor:\n" \
"#{clause.to_xml}")
"#{clause.to_xml}", severity: 1)
return
end
@refids << id
Expand All @@ -31,10 +31,12 @@ def validate_ref_dl(bib, clause)

def validate_ref_dl1(bib, id, clause)
bib["title"] or
@log.add("Bibliography", clause, "Reference #{id} is missing a title")
@log.add("Bibliography", clause, "Reference #{id} is missing a title",
severity: 1)
bib["docid"] or
@log.add("Bibliography", clause,
"Reference #{id} is missing a document identifier (docid)")
"Reference #{id} is missing a document identifier (docid)",
severity: 1)
end

def extract_from_p(tag, bib, key)
Expand Down
3 changes: 1 addition & 2 deletions lib/metanorma/standoc/cleanup_bibitem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def formattedref_spans(xmldoc)
def new_bibitem_from_formattedref_spans(bib)
ret = SpansToBibitem.new(bib).convert
ret.err.each do |e|
@log.add("Bibliography", bib, e[:msg])
e[:fatal] and @fatalerror << e[:msg]
@log.add("Bibliography", bib, e[:msg], severity: e[:fatal] ? 0 : 1)
end
ret.out
end
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/cleanup_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def para_index_cleanup1(para, prev, foll)
def ol_cleanup(doc)
doc.xpath("//ol[@explicit-type]").each do |x|
x.delete("explicit-type")
@log.add("Bibliography", x,
@log.add("Style", x,
"Style override set for ordered list")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/cleanup_boilerplate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def term_defs_boilerplate(div, source, term, _preface, isodoc)
source.each do |s|
@anchors[s["bibitemid"]] or
@log.add("Crossreferences", nil,
"term source #{s['bibitemid']} not referenced")
"term source #{s['bibitemid']} not referenced", severity: 1)
end
a = if source.empty? && term.nil? then @i18n.no_terms_boilerplate
else term_defs_boilerplate_cont(source, term, isodoc)
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/cleanup_footnotes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def footnote_block_remove(xmldoc, ids)

def footnote_block_error(fnote)
@log.add("Crossreferences", fnote,
"Could not resolve footnoteblock:[#{fnote.text}]")
"Could not resolve footnoteblock:[#{fnote.text}]", severity: 1)
fnote.children = "[ERROR]"
end

Expand Down
4 changes: 1 addition & 3 deletions lib/metanorma/standoc/cleanup_inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ def link_cleanup(xmldoc)
l["target"] = Addressable::URI.parse(l["target"]).to_s
rescue Addressable::URI::InvalidURIError
err = "Malformed URI: #{l['target']}"
@log.add("Anchors", l, err)
@fatalerror << err
warn err
@log.add("Anchors", l, err, severity: 0)
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/metanorma/standoc/cleanup_maths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def asciimath2mathml_indiv(elem)

def asciimath2mathml_err(text, expr)
err = "Malformed MathML: #{expr}\n#{text}"
@log.add("Maths", nil, err)
@fatalerror << err
warn err
@log.add("Maths", nil, err, severity: 0)
end

def asciimath2mathml_wrap(xml)
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def content(node)
def skip(node, name = nil)
name = name || node.node_name
w = "converter missing for #{name} node in Metanorma backend"
@log.add("AsciiDoc Input", node, w)
@log.add("AsciiDoc Input", node, w, severity: 1)
nil
end

Expand Down
15 changes: 8 additions & 7 deletions lib/metanorma/standoc/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ def thematic_break(_node)

def latex_parse1(text, block)
lxm_input = Unicode2LaTeX.unicode2latex(@c.decode(text))
results = Plurimath::Math.parse(lxm_input, "latex").
to_mathml(display_style: block)
results = Plurimath::Math.parse(lxm_input, "latex")
.to_mathml(display_style: block)
if results.nil?
@log.add("Math", nil,
"latexmlmath failed to process equation:\n#{lxm_input}")
"latexmlmath failed to process equation:\n#{lxm_input}",
severity: 1)
return
end
results.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
Expand All @@ -54,8 +55,8 @@ def latex_parse(text, xml, block)
latex = latex_parse1(text, block) or
return xml.stem type: "MathML", block: block
xml.stem type: "MathML", block: block do |s|
math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, "")).
elements[0]
math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
.elements[0]
math.delete("alttext")
s.parent.children = math
s << "<latexmath>#{text}</latexmath>"
Expand Down Expand Up @@ -104,8 +105,8 @@ def inline_quoted(node)
end

def hash2styles(role)
CSV.parse_line(role, liberal_parsing: true).
each_with_object({}) do |r, m|
CSV.parse_line(role, liberal_parsing: true)
.each_with_object({}) do |r, m|
kv = r.split(":", 2).map(&:strip)
case kv[0]
when "custom-charset"
Expand Down
9 changes: 3 additions & 6 deletions lib/metanorma/standoc/localbib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ def read_file(config)
def file_error(config)
msg = "Cannot process file #{config['file']} for local relaton " \
"data source #{config['key']}"
@parent.fatalerror << msg
@parent.log.add("Bibliography", nil, msg)
@parent.log.add("Bibliography", nil, msg, severity: 0)
""
end

def format_error(config)
msg = "Cannot process format #{config['format']} for local relaton " \
"data source #{config['key']}"
@parent.fatalerror << msg
@parent.log.add("Bibliography", nil, msg)
@parent.log.add("Bibliography", nil, msg, severity: 0)
{}
end

Expand All @@ -68,8 +66,7 @@ def get(id, file = default)

msg = "Cannot find reference #{id} for local relaton " \
"data source #{file}"
@parent.fatalerror << msg
@parent.log.add("Bibliography", nil, msg)
@parent.log.add("Bibliography", nil, msg, severity: 0)
Nokogiri::XML("<bibitem/>")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def refitem_render(xml, match, code)
def refitemcode(item, node)
m = NON_ISO_REF.match(item) and return refitem1code(item, m).compact
m = NON_ISO_REF1.match(item) and return refitem1code(item, m).compact
@log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}")
@log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}", severity: 1)
{}
end

Expand Down
4 changes: 2 additions & 2 deletions lib/metanorma/standoc/ref_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def reference_queue(results, size)
m[i.to_i] = { ref: ref }
if doc.is_a?(RelatonBib::RequestError)
@log.add("Bibliography", nil, "Could not retrieve #{ref[:code]}: " \
"no access to online site")
"no access to online site", severity: 1)
else m[i.to_i][:doc] = doc end
end
end
Expand Down Expand Up @@ -138,7 +138,7 @@ def fetch_ref(xml, code, year, **opts)
xml
rescue RelatonBib::RequestError
@log.add("Bibliography", nil, "Could not retrieve #{code}: " \
"no access to online site")
"no access to online site", severity: 1)
nil
end

Expand Down
4 changes: 2 additions & 2 deletions lib/metanorma/standoc/term_lookup_cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def lookup_refterm(node)
def remove_missing_ref(node, target)
if node.at("./parent::concept[@type = 'symbol']")
log.add("AsciiDoc Input", node,
remove_missing_ref_msg(node, target, :symbol))
remove_missing_ref_msg(node, target, :symbol), severity: 1)
remove_missing_ref_term(node, target, "symbol")
else
log.add("AsciiDoc Input", node,
remove_missing_ref_msg(node, target, :term))
remove_missing_ref_msg(node, target, :term), severity: 1)
remove_missing_ref_term(node, target, "term")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/terms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def extract_termsource_refs(text, node)
matched = TERM_REFERENCE_RE.match text
matched.nil? and @log.add("AsciiDoc Input", node,
"term reference not in expected format:" \
"#{text}")
"#{text}", severity: 1)
matched
end

Expand Down
24 changes: 12 additions & 12 deletions lib/metanorma/standoc/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ def content_validate(doc)
concept_validate(doc, "related", "preferred//name")
preferred_validate(doc)
table_validate(doc)
@fatalerror += requirement_validate(doc)
requirement_validate(doc).each do |e|
@log.add("Requirements", nil, e, severity: 0)

Check warning on line 26 in lib/metanorma/standoc/validate.rb

View check run for this annotation

Codecov / codecov/patch

lib/metanorma/standoc/validate.rb#L26

Added line #L26 was not covered by tests
end
image_validate(doc)
math_validate(doc)
@fatalerror.empty? or
clean_abort(@fatalerror.join("\n"), doc)
fatalerrors = @log.abort_messages
fatalerrors.empty? or
clean_abort(fatalerrors.join("\n"), doc)
end

MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
Expand All @@ -53,8 +56,7 @@ def math_validate_error(math, elem, error)
a and orig += "\n\tAsciimath original: #{@c.decode(a.children.to_xml)}"
l and orig += "\n\tLatexmath original: #{@c.decode(l.children.to_xml)}"
@log.add("Mathematics", elem,
"Invalid MathML: #{math}\n #{error}#{orig}")
@fatalerror << "Invalid MathML: #{math}"
"Invalid MathML: #{math}\n #{error}#{orig}", severity: 0)
end

def nested_asset_validate(doc)
Expand Down Expand Up @@ -92,7 +94,6 @@ def nested_asset_xref_report(outer, inner, _doc)
err2 = "There is a crossreference to an instance of #{inner.name} " \
"nested within #{outer.name}: #{i.to_xml}"
@log.add("Style", i, err2)
# @fatalerror << err2
end

def schema_validate(doc, schema)
Expand Down Expand Up @@ -149,8 +150,7 @@ def image_exists(doc)
Metanorma::Utils::datauri?(i["src"]) and next
expand_path(i["src"]) and next
@log.add("Images", i.parent,
"Image not found: #{i['src']}")
@fatalerror << "Image not found: #{i['src']}"
"Image not found: #{i['src']}", severity: 0)
end
end

Expand Down Expand Up @@ -189,9 +189,9 @@ def validate(doc)

def repeat_id_validate1(elem)
if @doc_ids[elem["id"]]
@log.add("Anchors", elem, "Anchor #{elem['id']} has already been " \
"used at line #{@doc_ids[elem['id']]}")
@fatalerror << "Multiple instances of same ID: #{elem['id']}"
@log.add("Anchors", elem,
"Anchor #{elem['id']} has already been " \
"used at line #{@doc_ids[elem['id']]}", severity: 0)
end
@doc_ids[elem["id"]] = elem.line
end
Expand All @@ -210,7 +210,7 @@ def xref_validate(doc)
m[x.text] = x
@doc_ids[x.text] and next
@log.add("Anchors", x.parent,
"Crossreference target #{x} is undefined")
"Crossreference target #{x} is undefined", severity: 1)
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions lib/metanorma/standoc/validate_section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def callouts_error(elem, callouts, annotations)
if callouts.size != annotations.size && !annotations.empty?
err = "mismatch of callouts (#{callouts.size}) and annotations " \
"(#{annotations.size})"
@log.add("AsciiDoc Input", elem, err)
@fatalerror << err
@log.add("AsciiDoc Input", elem, err, severity: 0)
end
end

Expand Down Expand Up @@ -58,15 +57,12 @@ def hanging_para_style(root)
end

def norm_ref_validate(doc)
found = false
doc.xpath("//references[@normative = 'true']/bibitem").each do |b|
docid = b.at("./docidentifier[@type = 'metanorma']") or next
/^\[\d+\]$/.match?(docid.text) or next
@log.add("Bibliography", b,
"Numeric reference in normative references")
found = true
"Numeric reference in normative references", severity: 0)
end
found and @fatalerror << "Numeric reference in normative references"
end
end
end
Expand Down
7 changes: 2 additions & 5 deletions lib/metanorma/standoc/validate_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,15 @@ def maxrows_validate(table, cells2d, tablechild, mode)
mode == "thead_row" and err = "cannot go outside #{tablechild}"
err = "Table rows in table #{err}: check rowspan"
if cells2d.any? { |x| x.size != cells2d.first.size }
@log.add("Table", table, err)
@fatalerror << err
@log.add("Table", table, err, severity: 0)
end
end

# if maxcols or maxrows negative, do not check them
def maxcols_check(col, maxcols, tcell)
if maxcols.positive? && col > maxcols
@log.add("Table", tcell, "Table exceeds maximum number of columns "\
"defined (#{maxcols})")
@fatalerror << "Table exceeds maximum number of columns defined "\
"(#{maxcols})"
"defined (#{maxcols})", severity: 0)
end
end
end
Expand Down
12 changes: 4 additions & 8 deletions lib/metanorma/standoc/validate_term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,16 @@ def iev_validate1(term, loc, xmldoc)
end
pref.include?(iev.downcase) or
@log.add("Bibliography", term, %(Term "#{pref[0]}" does not match ) +
%(IEV #{loc} "#{iev}"))
%(IEV #{loc} "#{iev}"), severity: 1)
end

def concept_validate(doc, tag, refterm)
found = false
concept_validate_ids(doc)
doc.xpath("//#{tag}/xref").each do |x|
@concept_ids[x["target"]] and next
@log.add("Anchors", x, concept_validate_msg(doc, tag, refterm, x))
found = true
@log.add("Anchors", x, concept_validate_msg(doc, tag, refterm, x),
severity: 0)
end
found and @fatalerror << "#{tag.capitalize} not cross-referencing " \
"term or symbol"
end

def concept_validate_ids(doc)
Expand Down Expand Up @@ -80,8 +77,7 @@ def preferred_validate(doc)
def preferred_validate_report(terms, locations)
terms.each do |e|
err = "Term #{e} occurs twice as preferred designation"
@log.add("Terms", locations[e], err)
@fatalerror << err
@log.add("Terms", locations[e], err, severity: 1)
end
end
end
Expand Down
Loading

0 comments on commit aca3178

Please sign in to comment.