Skip to content

Commit

Permalink
Revert prior style removal
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinderVosDeWael committed Oct 25, 2024
1 parent 247bedc commit 0bc20bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cmi_docx"
version = "0.3.2"
version = "0.3.3"
description = ".docx utilities"
authors = ["Reinder Vos de Wael <[email protected]>"]
license = "LGPL-2.1"
Expand All @@ -9,7 +9,7 @@ packages = [{include = "cmi_docx", from = "src"}]

[tool.poetry.dependencies]
python = ">=3.10"
python-docx = "^1.1.0"
python-docx = "^1.1.2"

[tool.poetry.group.dev.dependencies]
pytest = "^8.1.1"
Expand Down
10 changes: 6 additions & 4 deletions src/cmi_docx/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def insert_paragraph_by_text(
self,
index: int,
text: str,
style: str | None = None,
) -> docx_paragraph.Paragraph:
"""Inserts a paragraph into a document.
Expand All @@ -78,7 +79,7 @@ def insert_paragraph_by_text(
Returns:
The new paragraph.
"""
new_paragraph = self._insert_empty_paragraph(index)
new_paragraph = self._insert_empty_paragraph(index, style)
new_paragraph.add_run(text)
return new_paragraph

Expand Down Expand Up @@ -133,13 +134,13 @@ def all_paragraphs(self) -> list[docx_paragraph.Paragraph]:
return all_paragraphs

def _insert_empty_paragraph(
self,
index: int,
self, index: int, style: str | None = None
) -> docx_paragraph.Paragraph:
"""Inserts an empty paragraph at a given index.
Args:
index: The index to insert the paragraph at.
style: The style to apply to the paragraph.
Returns:
The new paragraph.
Expand All @@ -149,10 +150,11 @@ def _insert_empty_paragraph(
raise ValueError(f"Index {index} is out of range.")

if index == n_paragraphs:
new_paragraph = self.document.add_paragraph()
new_paragraph = self.document.add_paragraph(style=style)
else:
new_paragraph = new_paragraph = self.document.paragraphs[
index
]._insert_paragraph_before()
new_paragraph.style = style # type: ignore[assignment] # Mypy ignores setter types.

return new_paragraph

0 comments on commit 0bc20bf

Please sign in to comment.