Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
33 lines
930 B
Python
Executable File
33 lines
930 B
Python
Executable File
#! /usr/bin/env nix-shell
|
||
#! nix-shell -I nixpkgs=channel:nixos-unstable -i python3 -p python3 -p python3.pkgs.lxml
|
||
|
||
"""
|
||
Pandoc will try to resolve xrefs and replace them with regular links.
|
||
let’s replace them with links with empty labels which MyST
|
||
and our pandoc filters recognize as cross-references.
|
||
"""
|
||
|
||
import lxml.etree as ET
|
||
import sys
|
||
|
||
XLINK_NS = "http://www.w3.org/1999/xlink"
|
||
|
||
ns = {
|
||
"db": "http://docbook.org/ns/docbook",
|
||
}
|
||
|
||
|
||
if __name__ == '__main__':
|
||
assert len(sys.argv) >= 3, "usage: replace-xrefs-by-empty-links.py <input> <output>"
|
||
|
||
tree = ET.parse(sys.argv[1])
|
||
for xref in tree.findall(".//db:xref", ns):
|
||
text = ET.tostring(xref, encoding=str)
|
||
parent = xref.getparent()
|
||
link = parent.makeelement('link')
|
||
target_name = xref.get("linkend")
|
||
link.set(f"{{{XLINK_NS}}}href", f"#{target_name}")
|
||
parent.replace(xref, link)
|
||
|
||
tree.write(sys.argv[2])
|