Skip to content

Commit

Permalink
fix(xml2rfc): return better anchor for 3GPP docs
Browse files Browse the repository at this point in the history
  • Loading branch information
strogonoff committed Jul 28, 2022
1 parent 107ddf6 commit 29cac5c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions bibxml/xml2rfc_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,20 @@ class ThreeGPPPAdapter(Xml2rfcAdapter):
"""

@classmethod
def reverse(self, item: BibliographicItem) -> List[ReversedRef]:
def resolve_num(cls, item: BibliographicItem) -> Optional[str]:
if ((docid := get_primary_docid(item.docid))
and docid.type == '3GPP'):
num = (
return (
docid.id.split(':')[0].
removeprefix('3GPP ').
removeprefix('TS ').
removeprefix('TR ').
replace(' ', '.'))
return None

@classmethod
def reverse(cls, item: BibliographicItem) -> List[ReversedRef]:
if (num := cls.resolve_num(item)):
return [
(f"3GPP.{num}", None),
(f"SDO-3GPP.{num}", None),
Expand All @@ -386,6 +391,13 @@ def fetch_refs(self) -> Sequence[RefData]:
'date[*]': '@.type == "published"',
}, limit=1, exact=True)

def format_anchor(self) -> str:
if (self.resolved_item is not None
and (num := self.resolve_num(self.resolved_item))):
return f'SDO-3GPP.{num}'
else:
raise RuntimeError("Cannot format anchor: item not resolved")


@register_adapter('bibxml6')
class IeeeAdapter(Xml2rfcAdapter):
Expand Down

0 comments on commit 29cac5c

Please sign in to comment.