Skip to content

Commit ab8cf3d

Browse files
Patch filters (#1551)
This PR adds a patch to the `filter_links` Pandoc filter to process inline HTML. Two demos use this directive and are crashing the objects.inv build. Verified that all demos now build [here](https://github.com/PennyLaneAI/qml/actions/runs/17861828175).
1 parent 14fc98a commit ab8cf3d

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

documentation/reference_demo/demo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@
571571
# Example of an admonition directive.
572572

573573
# %%
574-
# Links
575-
# -----
574+
# Links and Inlines
575+
# -----------------
576576
#
577577
# Example of an `external link <https://pennylane.ai/qml>`_.
578578
#
@@ -597,6 +597,8 @@
597597
# Same as above, but without a custom label: :mod:`~pennylane.qnn`.
598598
#
599599
# Example of a reference link: :ref:`reference_link`. These aren't supported in the demos.
600+
#
601+
# Example of an inline html directive: :html:`<a href="https://pennylane.ai" target="_blank">An inline HTML link to pennylane.ai</a>`.
600602

601603
# %%
602604
# Make some reference like this [#Jordan2024]_ and this [#Bartschi2019]_ in the demo and they

lib/filter_links.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66
from typing import Any, Dict
77
import sphobjinv as soi
8-
from pandocfilters import toJSONFilter, Link
8+
from pandocfilters import toJSONFilter, Link, RawInline
99

1010
DEMOS_URL = "https://pennylane.ai/qml/demos/"
1111
PL_OBJ_INV_URL = "https://docs.pennylane.ai/en/stable/"
@@ -67,15 +67,17 @@ def filter_links(key, value, format, _):
6767
[[_, classes, role], body] = value
6868

6969
if "interpreted-text" in classes:
70-
text, key = parse_body(body)
71-
72-
# The doc type could be a demo, so needs special treatment
73-
if "doc" in role[0]:
74-
name, link = process_doc_link(text, key)
70+
if "html" in role[0]:
71+
return RawInline("markdown", body)
7572
else:
76-
name, link = process_link(text, key)
73+
text, key = parse_body(body)
74+
# The doc type could be a demo, so needs special treatment
75+
if "doc" in role[0]:
76+
name, link = process_doc_link(text, key)
77+
else:
78+
name, link = process_link(text, key)
7779

78-
return Link(["",[],[]], pandocify_string(name), [link,""])
80+
return Link(["",[],[]], pandocify_string(name), [link,""])
7981

8082
if __name__ == '__main__':
8183
pl_obj_inv = make_named_inventory(soi.Inventory(url=PL_OBJ_INV_URL+"objects.inv"))

0 commit comments

Comments
 (0)