Skip to content

Commit

Permalink
Fix for whitespace handling in link lists (#355)
Browse files Browse the repository at this point in the history
* Fix for whitespace handling in link lists

* Removed whitespace in  option value's list

* Refactored code for whitespace handling

Co-authored-by: Haiyang Zhang <haiyang.zhang@useblocks.com>

Fixes #349
  • Loading branch information
danwos authored Aug 17, 2021
1 parent 06d10e2 commit b01daf7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/directives/needextend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The argument of ``needextend`` must be a :ref:`filter_string`, which defines the
:status: open
:author: Foo
:tags: tag_1, tag_2
:links: FEATURE_1

This requirement got modified.

Expand All @@ -64,6 +65,8 @@ The argument of ``needextend`` must be a :ref:`filter_string`, which defines the
:status: closed
:+author: and me
:+tags: new_tag
:+links: FEATURE_2, FEATURE_3


Single need modification
------------------------
Expand Down
6 changes: 6 additions & 0 deletions sphinxcontrib/needs/directives/needextend.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ def process_needextend(app, doctree, fromdocname):
# If we need to handle a list
if option_name in list_names:
for link in re.split(";|,", value):
# Remove whitespaces
link = link.strip()
if link not in need[option_name]:
need[option_name].append(link)

# If we manipulate links, we need to set all the reference in the target need
# under e.g. links_back
if option_name in link_names:
for ref_need in re.split(";|,", value):
# Remove whitespaces
ref_need = ref_need.strip()
if found_need["id"] not in app.env.needs_all_needs[ref_need][f"{option_name}_back"]:
app.env.needs_all_needs[ref_need][f"{option_name}_back"] += [found_need["id"]]

Expand Down Expand Up @@ -140,6 +144,8 @@ def process_needextend(app, doctree, fromdocname):

need[option] = []
for link in re.split(";|,", value):
# Remove whitespaces
link = link.strip()
if link not in need[option]:
need[option].append(link)

Expand Down
8 changes: 8 additions & 0 deletions tests/doc_test/doc_needextend/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Need extend

Had the link ``extend_test_003``, got another one ``extend_test_004``.

.. story:: needextend Example 7
:id: extend_test_007
:links: extend_test_003


.. needextend:: extend_test_003
:links: extend_test_004

Expand All @@ -42,3 +47,6 @@ Need extend

.. needextend:: extend_test_006
:+links: extend_test_004

.. needextend:: extend_test_007
:+links: extend_test_004, extend_test_005
2 changes: 1 addition & 1 deletion tests/test_needextend.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def test_doc_needextend_html(app, status, warning):
assert (
'<span class="needs_data_container"><span class="needs_data">tag_1</span><span class="needs_spacer">, '
'</span><span class="needs_data">new_tag</span><span class="needs_spacer">, '
'</span><span class="needs_data"> another_tag</span></span>' in page_1__html
'</span><span class="needs_data">another_tag</span></span>' in page_1__html
)

0 comments on commit b01daf7

Please sign in to comment.