Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 11 additions & 8 deletions sphinx_needs/directives/list2need.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def run(self) -> Sequence[nodes.Node]:
if not delimiter:
delimiter = "."

content_raw = "\n".join(self.content)
types_raw = self.options.get("types")
if not types_raw:
raise SphinxWarning("types must be set.")
Expand Down Expand Up @@ -114,10 +113,13 @@ def run(self) -> Sequence[nodes.Node]:
# Retrieve tags defined at list level
tags = self.options.get("tags", "")

_, content_first_line = self.state_machine.get_source_and_line(
self.content_offset + 1
)

list_needs = []
# Storing the data in a sorted list
for content_line in content_raw.split("\n"):
# for groups in line.findall(content_raw):
for content_lineno, content_line in enumerate(self.content):
match = LINE_REGEX.search(content_line)
if not match:
continue
Expand Down Expand Up @@ -173,6 +175,7 @@ def run(self) -> Sequence[nodes.Node]:
"content": content.lstrip(),
"level": level,
"options": {},
"lineno": content_first_line + content_lineno,
}
list_needs.append(need)
else:
Expand All @@ -184,7 +187,6 @@ def run(self) -> Sequence[nodes.Node]:
)

# Finally creating the rst code
overall_text = []
for index, list_need in enumerate(list_needs):
# Search for meta data in the complete title/content
search_string = list_need["title"] + list_need["content"]
Expand Down Expand Up @@ -226,11 +228,12 @@ def run(self) -> Sequence[nodes.Node]:
if presentation == "nested":
indented_text_list = [" " * list_need["level"] + x for x in text_list]
text_list = indented_text_list
overall_text += text_list

self.state_machine.insert_input(
overall_text, self.state_machine.document.attributes["source"]
)
self.state_machine.insert_input(
text_list,
self.state_machine.document.attributes["source"]
+ "\0%d" % list_need["lineno"],
)

return []

Expand Down
10 changes: 8 additions & 2 deletions sphinx_needs/directives/need.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,15 @@ def run(self) -> Sequence[nodes.Node]:
self._log_warning(f"Invalid value for '{key}' option: {err}")
return []

source_path, source_lineno = self.state_machine.get_source_and_line(self.lineno)
if "\0" in source_path:
# Retrieve line number encoded in source name
source_path, source_lineno = source_path.split("\0")
source_lineno = int(source_lineno)
docname = self.env.path2doc(source_path)
source = NeedItemSourceDirective(
docname=self.env.docname,
lineno=self.lineno,
docname=source_path if docname is None else docname,
lineno=source_lineno,
lineno_content=self.content_offset + 1,
)

Expand Down
Loading