diff --git a/demo/73-comments.ts b/demo/73-comments.ts index fffe22df93..3c1da71454 100644 --- a/demo/73-comments.ts +++ b/demo/73-comments.ts @@ -5,7 +5,34 @@ import { Document, Packer, Paragraph, TextRun, CommentRangeStart, CommentRangeEn const doc = new Document({ comments: { - children: [{ id: 0, author: "Ray Chen", date: new Date(), text: "comment text content" }], + children: [ + { + id: 0, + author: "Ray Chen", + date: new Date(), + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: "some initial text content", + }), + ], + }), + new Paragraph({ + children: [ + new TextRun({ + text: "comment text content", + }), + new TextRun({ text: "", break: 1 }), + new TextRun({ + text: "More text here", + bold: true, + }), + ], + }), + ], + }, + ], }, sections: [ { diff --git a/src/file/paragraph/run/comment-run.spec.ts b/src/file/paragraph/run/comment-run.spec.ts index 62d3a624b8..1fa9aab101 100644 --- a/src/file/paragraph/run/comment-run.spec.ts +++ b/src/file/paragraph/run/comment-run.spec.ts @@ -2,6 +2,8 @@ import { expect } from "chai"; import * as sinon from "sinon"; import { Formatter } from "@export/formatter"; + +import { Paragraph } from "../paragraph"; import { Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments } from "./comment-run"; describe("CommentRangeStart", () => { @@ -56,7 +58,7 @@ describe("Comment", () => { it("should create", () => { const component = new Comment({ id: 0, - text: "test-comment", + children: [new Paragraph("test-comment")], date: new Date("1999-01-01T00:00:00.000Z"), }); const tree = new Formatter().format(component); @@ -88,7 +90,7 @@ describe("Comment", () => { it("should create by using default date", () => { const component = new Comment({ id: 0, - text: "test-comment", + children: [new Paragraph("test-comment")], }); const tree = new Formatter().format(component); expect(tree).to.deep.equal({ @@ -125,12 +127,12 @@ describe("Comments", () => { children: [ { id: 0, - text: "test-comment", + children: [new Paragraph("test-comment")], date: new Date("1999-01-01T00:00:00.000Z"), }, { id: 1, - text: "test-comment-2", + children: [new Paragraph("test-comment-2")], date: new Date("1999-01-01T00:00:00.000Z"), }, ], diff --git a/src/file/paragraph/run/comment-run.ts b/src/file/paragraph/run/comment-run.ts index 626f4ccba9..f204f7ddcd 100644 --- a/src/file/paragraph/run/comment-run.ts +++ b/src/file/paragraph/run/comment-run.ts @@ -1,11 +1,9 @@ -import { Paragraph } from "@file/paragraph"; +import { FileChild } from "@file/file-child"; import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; -import { TextRun } from "./text-run"; - export interface ICommentOptions { readonly id: number; - readonly text: string; + readonly children: readonly FileChild[]; readonly initials?: string; readonly author?: string; readonly date?: Date; @@ -120,7 +118,7 @@ export class CommentReference extends XmlComponent { } export class Comment extends XmlComponent { - public constructor({ id, initials, author, date = new Date(), text }: ICommentOptions) { + public constructor({ id, initials, author, date = new Date(), children }: ICommentOptions) { super("w:comment"); this.root.push( @@ -132,7 +130,9 @@ export class Comment extends XmlComponent { }), ); - this.root.push(new Paragraph({ children: [new TextRun(text)] })); + for (const child of children) { + this.root.push(child); + } } } export class Comments extends XmlComponent {