Skip to content

Commit 9219df1

Browse files
committed
fix: support spaces in rst ref text
1 parent 9b71a90 commit 9219df1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

_extensions/interlinks/interlinks.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
inventory = {}
88

99

10+
class ConfigError(Exception):
11+
pass
12+
13+
1014
def load_mock_inventory(items: "dict[str, str]"):
1115
for k, v in items.items():
1216
inventory[k] = v
@@ -75,7 +79,7 @@ def parse_rst_style_ref(full_text):
7579

7680
pf.debug(full_text)
7781

78-
m = re.match(r"(?P<text>.+?)\<(?P<ref>[a-zA-Z\.\-: ]+)\>", full_text)
82+
m = re.match(r"(?P<text>.+?)\<(?P<ref>[a-zA-Z\.\-: _]+)\>", full_text)
7983
if m is None:
8084
# TODO: print a warning or something
8185
return full_text, None
@@ -98,7 +102,17 @@ def visit(el, doc):
98102
def visit(el: pf.MetaList, doc):
99103
meta = doc.get_metadata()
100104

101-
for doc_name, cfg in meta["interlinks"]["sources"].items():
105+
try:
106+
sources = meta["interlinks"]["sources"]
107+
except KeyError:
108+
raise ConfigError(
109+
"No interlinks.sources field detected in your metadata."
110+
"Please add this to your header:\n\n"
111+
"interlinks:"
112+
"\n sources:"
113+
"\n - <source_name>: {url: ..., inv: ..., fallback: ... }"
114+
)
115+
for doc_name, cfg in sources.items():
102116
json_data = json.load(open(cfg["fallback"]))
103117

104118
for item in json_data["items"]:

0 commit comments

Comments
 (0)