Skip to content

Commit 672dbeb

Browse files
Fix faulty styling on paragraph insertion
1 parent c0d1dcd commit 672dbeb

6 files changed

Lines changed: 30 additions & 36 deletions

File tree

SECURITY.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ Child Mind Institute values the security of our users, data, and servers. We tak
44

55
## Supported Versions
66

7-
MODIFY:
8-
9-
Note which version(s) will receive security updates. For example:
10-
11-
| Version | Supported |
12-
| ------- | ------------------ |
13-
| 1.0.x | :white_check_mark: |
14-
| 0.9.x | :x: |
7+
Only the most recent version will receive security updates.
158

169
## Reporting Vulnerabilities
1710

18-
To report security vulnerabilities, please do NOT use our issues page. Instead, kindly email us at reinder.vosdewael@childmind.org. Please refrain from using other communication channels.
11+
To report security vulnerabilities, please do NOT use our issues page. Instead, kindly email us at dair@childmind.org. Please refrain from using other communication channels.
1912

2013
For non-security-related issues, we welcome your input and feedback on our issues page. Feel free to share your ideas and suggestions to help us improve our services.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cmi_docx"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = ".docx utilities"
55
authors = ["Reinder Vos de Wael <reinder.vosdewael@childmind.org>"]
66
license = "LGPL-2.1"

src/cmi_docx/document.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def insert_paragraph_by_text(
7777
Returns:
7878
The new paragraph.
7979
"""
80-
new_paragraph = self._insert_empty_paragraph(index)
81-
new_paragraph.add_run(text, style=style)
80+
new_paragraph = self._insert_empty_paragraph(index, style)
81+
new_paragraph.add_run(text)
8282
return new_paragraph
8383

8484
def insert_paragraph_by_object(
@@ -97,7 +97,7 @@ def insert_paragraph_by_object(
9797
"""
9898
new_paragraph = self._insert_empty_paragraph(index)
9999
for paragraph_run in paragraph.runs:
100-
new_paragraph.add_run(paragraph_run.text, paragraph_run.style)
100+
new_paragraph.add_run(paragraph_run.text)
101101
return new_paragraph
102102

103103
def insert_image(
@@ -131,11 +131,14 @@ def all_paragraphs(self) -> list[docx_paragraph.Paragraph]:
131131
)
132132
return all_paragraphs
133133

134-
def _insert_empty_paragraph(self, index: int) -> docx_paragraph.Paragraph:
134+
def _insert_empty_paragraph(
135+
self, index: int, style: str | None = None
136+
) -> docx_paragraph.Paragraph:
135137
"""Inserts an empty paragraph at a given index.
136138
137139
Args:
138140
index: The index to insert the paragraph at.
141+
style: The style to apply to the paragraph.
139142
140143
Returns:
141144
The new paragraph.
@@ -145,10 +148,11 @@ def _insert_empty_paragraph(self, index: int) -> docx_paragraph.Paragraph:
145148
raise ValueError(f"Index {index} is out of range.")
146149

147150
if index == n_paragraphs:
148-
new_paragraph = self.document.add_paragraph()
151+
new_paragraph = self.document.add_paragraph(style=style)
149152
else:
150153
new_paragraph = new_paragraph = self.document.paragraphs[
151154
index
152155
]._insert_paragraph_before()
156+
new_paragraph.style = style
153157

154158
return new_paragraph

src/cmi_docx/table.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from docx.enum import text
55
from docx.oxml import ns
66

7-
from cmi_docx import paragraph, utils
7+
from cmi_docx import paragraph
88

99

1010
class ExtendCell:
@@ -60,11 +60,23 @@ def format(
6060
if background_rgb is not None:
6161
shading = oxml.parse_xml(
6262
(
63-
r'<w:shd {} w:fill="'
64-
+ f"{utils.rgb_to_hex(*background_rgb)}"
65-
+ r'"/>'
63+
r'<w:shd {} w:fill="' + f"{rgb_to_hex(*background_rgb)}" + r'"/>'
6664
).format(
6765
ns.nsdecls("w"),
6866
),
6967
)
7068
self.cell._tc.get_or_add_tcPr().append(shading) # noqa: SLF001
69+
70+
71+
def rgb_to_hex(r: int, g: int, b: int) -> str:
72+
"""Converts RGB values to a hexadecimal color code.
73+
74+
Args:
75+
r: The red component of the RGB color.
76+
g: The green component of the RGB color.
77+
b: The blue component of the RGB color.
78+
79+
Returns:
80+
The hexadecimal color code representing the RGB color.
81+
"""
82+
return f"#{r:02x}{g:02x}{b:02x}".upper()

src/cmi_docx/utils.py

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from cmi_docx import utils
5+
from cmi_docx import table
66

77

88
@pytest.mark.parametrize(
@@ -30,4 +30,4 @@ def test_rgb_to_hex(
3030
hexadecimal: str,
3131
) -> None:
3232
"""Tests converting RGB to hex."""
33-
assert utils.rgb_to_hex(*rgb) == hexadecimal
33+
assert table.rgb_to_hex(*rgb) == hexadecimal

0 commit comments

Comments
 (0)