Rewrite asciidoctor xrefs in text to resolve properly in refpages. Xrefs which are to refpages are rewritten to link to those refpages. The remainder are rewritten to generate external links into the supplied specification document URL. - text - string to rewrite, or None - spec
(text, specURL)
| 476 | remapPatterns.specLinkSubstitute = None |
| 477 | |
| 478 | def xrefRewrite(text, specURL): |
| 479 | """Rewrite asciidoctor xrefs in text to resolve properly in refpages. |
| 480 | Xrefs which are to refpages are rewritten to link to those |
| 481 | refpages. The remainder are rewritten to generate external links into |
| 482 | the supplied specification document URL. |
| 483 | |
| 484 | - text - string to rewrite, or None |
| 485 | - specURL - URL to target |
| 486 | |
| 487 | Returns rewritten text, or None, respectively""" |
| 488 | |
| 489 | if text is None: |
| 490 | return text |
| 491 | |
| 492 | global remapState, remapPatterns |
| 493 | |
| 494 | # Define specLinkSubstitute, a callback function passed to re.subn to |
| 495 | # rewrite <<anchor, text>> for the targeted output form (Antora or |
| 496 | # regular HTML refpages). |
| 497 | if remapState.antora: |
| 498 | # This should never happen, because the refpages for Antora are |
| 499 | # generated by extraction from the already transformed spec source, |
| 500 | # and xrefs should already have been rewritten. |
| 501 | # If it needs to work for some reason, it will be necessary to |
| 502 | # import xrefMap.py and pageMap.py to determine the Antora page to |
| 503 | # link to. |
| 504 | |
| 505 | # For Antora, rewrite the anchor into an Antora resource ID |
| 506 | # containing that anchor in the specification module. |
| 507 | # This is more complex than a static regular expression allows. |
| 508 | |
| 509 | def rewriteResourceID(match, module): |
| 510 | anchor = match.group(1) |
| 511 | text = match.group(2) |
| 512 | |
| 513 | return f'xref:{module}{pagename}#{anchor}[{text}]' |
| 514 | |
| 515 | specLinkSubstitute = lambda match: rewriteResourceID(match, remapState.module) |
| 516 | else: |
| 517 | # For the standalone refpages, rewrite relative to the HTML spec |
| 518 | # URL. |
| 519 | |
| 520 | def substituteURL(match, specURL): |
| 521 | anchor = match.group(1) |
| 522 | text = match.group(2) |
| 523 | |
| 524 | return f'link:{specURL}#{anchor}[{text}^]' |
| 525 | |
| 526 | specLinkSubstitute = lambda match: substituteURL(match, specURL) |
| 527 | |
| 528 | # Substitute |
| 529 | text, _ = remapPatterns.refLinkPattern.subn(remapPatterns.refLinkSubstitute, text) |
| 530 | text, _ = remapPatterns.refLinkTextPattern.subn(remapPatterns.refLinkTextSubstitute, text) |
| 531 | text, _ = remapPatterns.specLinkPattern.subn(specLinkSubstitute, text) |
| 532 | |
| 533 | return text |
| 534 | |
| 535 | def emitPage(baseDir, specDir, pi, file): |
no test coverage detected