Skip to content

Commit

Permalink
feat: Support paragraph color (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuweb authored Oct 15, 2024
1 parent 60d9492 commit 6fdf81d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docx-core/src/documents/elements/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ impl Paragraph {
self
}

pub fn color(mut self, c: impl Into<String>) -> Self {
self.property.run_property = self.property.run_property.color(c);
self
}

pub fn bold(mut self) -> Self {
self.property.run_property = self.property.run_property.bold();
self
Expand Down
4 changes: 4 additions & 0 deletions docx-wasm/js/paragraph-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ export const setParagraphProperty = <T extends wasm.Paragraph | wasm.Style>(
target = target.bold() as T;
}

if (property.runProperty.color) {
target = target.color(property.runProperty.color) as T;
}

if (typeof property.lineSpacing !== "undefined") {
const spacing = buildLineSpacing(property);
if (spacing) {
Expand Down
5 changes: 5 additions & 0 deletions docx-wasm/js/paragraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ export class Paragraph {
return this;
}

color(color: string) {
this.property.runProperty = { ...this.property.runProperty, color };
return this;
}

bold() {
this.property.runProperty = { ...this.property.runProperty, bold: true };
return this;
Expand Down
5 changes: 5 additions & 0 deletions docx-wasm/src/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ impl Paragraph {
self
}

pub fn color(mut self, c: &str) -> Self {
self.0 = self.0.color(c);
self
}

pub fn bold(mut self) -> Self {
self.0 = self.0.bold();
self
Expand Down

0 comments on commit 6fdf81d

Please sign in to comment.