formatter/typst.py: add placeholder label for section references

This commit is contained in:
dogeystamp 2023-07-23 20:01:36 -04:00
parent 35267cfa34
commit b33da2a881
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38

View File

@ -19,19 +19,21 @@ def format_pdf_link(ref: PDFReference) -> str:
format_path = str(ref.filepath.absolute())
params = {}
default_label = ""
match ref:
case PDFPage():
params["page"] = ref.page
case PDFSection():
params["section"] = ref.title
default_label = ref.title
case _ as obj:
assert_never(obj)
if relative:
return f'#lref("{format_path}?{urlencode(params)}", pdfref: true)[]'
return f'#lref("{format_path}?{urlencode(params)}", pdfref: true)[{default_label}]'
else:
return f'#link("pdfref://{format_path}?{urlencode(params)}")[]'
return f'#link("pdfref://{format_path}?{urlencode(params)}")[{default_label}]'
def ref(ref: Reference) -> str:
"""Formats a Reference."""