Skip to content

Commit

Permalink
fix: items remove and insert (not replace)
Browse files Browse the repository at this point in the history
Refs: #1
  • Loading branch information
attakei committed Nov 4, 2024
1 parent 3d03a27 commit 716fd16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/atsphinx/linebreak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def inject_line_break(app: Sphinx, doctree: nodes.document):
splitted = [(nodes.Text(t), line_break()) for t in text.split("\n")]
items = [item for parts in splitted for item in parts]
p = text.parent
p.children = items[:-1]
pos = p.children.index(text)
p.children.remove(text)
for idx, item in enumerate(items):
p.children.insert(pos + idx, item)


def setup(app: Sphinx): # noqa: D103
Expand Down
2 changes: 2 additions & 0 deletions tests/test_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ def test__it(app: SphinxTestApp):
app.build()
soup = BeautifulSoup((app.outdir / "index.html").read_text(), "lxml")
assert soup.p.br
assert soup.p.text == "This isa pen."
soup = BeautifulSoup((app.outdir / "index2.html").read_text(), "lxml")
assert soup.p.br
assert soup.p.text == "This isa pen."

0 comments on commit 716fd16

Please sign in to comment.