Commits

Anonymous committed 7e7c569

Enable usage of <a> instead of <span> for xrefs. Also fix instance_elements in xspecxref.py to match xref.py. (second try)

Comments (0)

Files changed (3)

     parser.add_argument("--use-strict", action="store_true",
                         dest="use_strict", help=SUPPRESS)
 
+    parser.add_argument("--xref-use-a", action="store_true",
+                        dest="xref_use_a", help=SUPPRESS)
+
     parser.add_argument("--pubdate", action="store", type=str,
                         dest="publication_date", metavar="1 Sep 2022",
                         help="Set the date this document will be published.")

anolislib/processes/xref.py

 from anolislib import utils
 
 instance_elements = frozenset(["span", "code"])
+instance_elements_a = frozenset(["a", "code"])
 w3c_instance_elements = frozenset(["abbr", "acronym", "b", "bdo", "big",
                                    "code", "del", "em", "i", "ins",
                                    "kbd", "label", "legend", "q", "samp",
     def addReferences(self, ElementTree, w3c_compat=False,
                       w3c_compat_xref_elements=False,
                       w3c_compat_xref_a_placement=False,
+                      xref_use_a=False,
                       use_strict=False,
                       dump_backrefs=False,
                       **kwargs):
         for element in ElementTree.iter(tag=etree.Element):
-            if element.tag in instance_elements or \
+            if (not xref_use_a and element.tag in instance_elements) or \
+               (xref_use_a and element.tag in instance_elements_a and element.get("href") is None) or \
                (w3c_compat or w3c_compat_xref_elements) and \
                element.tag in w3c_instance_elements:
                 term = self.getTerm(element, w3c_compat=w3c_compat, **kwargs)
                                 break
 
                     if goodParentingAndChildren and element.get("data-anolis-spec") is None:
-                        if element.tag == "span":
+                        if element.tag == "span" or element.tag == "a":
                             element.tag = "a"
                             element.set("href", "#" + self.dfns[term])
                             link = element

anolislib/processes/xspecxref.py

 
 from anolislib import utils
 
-instance_elements = frozenset(["span", "abbr", "code", "var", "i"])
+instance_elements = frozenset(["span", "code"])
+instance_elements_a = frozenset(["a", "code"])
 w3c_instance_elements = frozenset(["abbr", "acronym", "b", "bdo", "big",
                    "code", "del", "em", "i", "ins",
                    "kbd", "label", "legend", "q", "samp",
   def addReferences(self, ElementTree, w3c_compat=False,
                     w3c_compat_xref_elements=False,
                     w3c_compat_xref_a_placement=False,
+                    xref_use_a=False,
                     use_strict=False,
                     **kwargs):
     for element in ElementTree.iter(tag=etree.Element):
-      if ((element.tag in instance_elements
+      if (((not xref_use_a and element.tag in instance_elements)
+          or (xref_use_a and element.tag in instance_elements_a and element.get("href") is None)
           or (w3c_compat or w3c_compat_xref_elements)
           and element.tag in w3c_instance_elements)
           and (element.get("data-anolis-spec") is not None)):
               break
 
         if goodParentingAndChildren:
-          if element.tag == "span":
+          if element.tag == "span" or element.tag == "a":
             element.tag = "a"
             element.set("href", obj["url"] + obj["values"][term])
           else: