Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for multiple regex matches #1353

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions sphinx_needs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,25 +457,22 @@ def match_string_link(
try:
link_name = None
link_url = None
link_conf = matching_link_confs[
0
] # We only handle the first matching string_link
match = link_conf["regex_compiled"].search(data)
if match:
render_content = match.groupdict()
link_url = link_conf["url_template"].render(
**render_content, **render_context
)
link_name = link_conf["name_template"].render(
**render_content, **render_context
)
link_conf = matching_link_confs
for lc in link_conf:
match = lc["regex_compiled"].search(data)
if match:
render_content = match.groupdict()
link_url = lc["url_template"].render(**render_content, **render_context)
link_name = lc["name_template"].render(
**render_content, **render_context
)

# if no string_link match was made, we handle it as normal string value
ref_item = (
nodes.reference(link_name, link_name, refuri=link_url)
if link_name
else nodes.Text(text_item)
)
# if no string_link match was made, we handle it as normal string value
ref_item = (
nodes.reference(link_name, link_name, refuri=link_url)
if link_name
else nodes.Text(text_item)
)

except Exception as e:
log_warning(
Expand Down