From c14c72c70c5f2558964bc326ca80a1107caf5c06 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Mon, 16 Jun 2025 11:57:47 -0700 Subject: [PATCH 1/2] Add --lax-validation flag --- xml2rfc/run.py | 2 ++ xml2rfc/writers/base.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/xml2rfc/run.py b/xml2rfc/run.py index 84dff544..e45aa320 100755 --- a/xml2rfc/run.py +++ b/xml2rfc/run.py @@ -233,6 +233,8 @@ def main(): help='generate utf8 output') plain_options.add_argument('-v', '--verbose', action='store_true', help='print extra information') + plain_options.add_argument('--lax-validation', action='store_true', default=False, + help='Treat schema validation errors as warnings (v3 writers)') value_options = optionparser.add_argument_group('Generic Options with Values') diff --git a/xml2rfc/writers/base.py b/xml2rfc/writers/base.py index 5723cd2c..02d223e3 100644 --- a/xml2rfc/writers/base.py +++ b/xml2rfc/writers/base.py @@ -81,6 +81,7 @@ 'info': False, 'info_base_url': 'https://www.rfc-editor.org/info/', 'inline_version_info': True, + 'lax_validation': False, 'legacy': False, 'legacy_date_format': False, 'legacy_list_symbols': False, @@ -2158,7 +2159,7 @@ def validate_before(self, e, p): version = self.root.get('version', '3') if version not in ['3', ]: self.die(self.root, 'Expected version="3", but found "%s"' % version) - if not self.validate('before'): + if not self.validate('before', warn=self.options.lax_validation): self.note(None, "Schema validation failed for input document") self.validate_draft_name() @@ -2186,7 +2187,7 @@ def validate_after(self, e, p): attrib = copy.deepcopy(e.attrib) e.attrib.clear() # - if not self.validate('after', warn=True): + if not self.validate('after', warn=self.options.lax_validation): self.note(None, "Schema validation failed for input document") else: self.root.set('version', '3') From 136c2d97212baba1b3bfb9aa0573271108327e82 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Mon, 16 Jun 2025 12:19:44 -0700 Subject: [PATCH 2/2] Make sure --lax-validation makes it all the way through. --- xml2rfc/writers/preptool.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xml2rfc/writers/preptool.py b/xml2rfc/writers/preptool.py index 9d82badc..3af67ffc 100644 --- a/xml2rfc/writers/preptool.py +++ b/xml2rfc/writers/preptool.py @@ -1532,7 +1532,7 @@ def ol_add_counter(self, e, p): # of the "target" attribute with no other adornment. Issue a # warning if the "derivedContent" attribute already exists and has a # different value from what was being filled in. - def build_derived_content(self, e): + def build_derived_content(self, e, lax_validation=False): def split_pn(t, pn): if pn is None: self.die(e, "Expected to find a pn= attribute on <%s anchor='%s'> when processing , but found none" % (t.tag, t.get('anchor')), trace=True) @@ -1554,7 +1554,9 @@ def get_name(t): t = self.root.find('.//*[@pn="%s"]'%(target, )) if t is None: t = self.root.find('.//*[@slugifiedName="%s"]'%(target, )) - if t is None: + if t is None and lax_validation: + return e, "[PLACEHOLDER: %s]" % target + elif t is None: self.die(e, "Found no element to match the target attribute '%s'" % (target, )) # p = t @@ -1636,7 +1638,7 @@ def get_name(t): def element_xref(self, e, p): section = e.get('section') relative = e.get('relative') - t, content = self.build_derived_content(e) + t, content = self.build_derived_content(e, lax_validation=self.options.lax_validation) is_toc = p.get('pn', '').startswith('section-toc') if not (section or relative): attr = e.get('derivedContent')