diff --git a/demo/54-track-revisions.ts b/demo/54-track-revisions.ts index 01d96082b8..a0cc47a03b 100644 --- a/demo/54-track-revisions.ts +++ b/demo/54-track-revisions.ts @@ -1,7 +1,19 @@ // Track Revisions aka. "Track Changes" // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Document, Packer, Paragraph, TextRun, ShadingType, DeletedTextRun, InsertedTextRun, Footer, PageNumber, AlignmentType, FootnoteReferenceRun } from "../build"; +import { + AlignmentType, + DeletedTextRun, + Document, + Footer, + FootnoteReferenceRun, + InsertedTextRun, + Packer, + PageNumber, + Paragraph, + ShadingType, + TextRun, +} from "../build"; /* For reference, see @@ -17,7 +29,7 @@ import { Document, Packer, Paragraph, TextRun, ShadingType, DeletedTextRun, Inse const doc = new Document({ footnotes: [ new Paragraph({ - children:[ + children: [ new TextRun("This is a footnote"), new DeletedTextRun({ text: " with some extra text which was deleted", @@ -30,19 +42,20 @@ const doc = new Document({ id: 1, author: "Firstname Lastname", date: "2020-10-06T09:05:00Z", - }) - ] + }), + ], }), ], + features: { + trackRevisions: true, + }, }); -doc.Settings.addTrackRevisions() - const paragraph = new Paragraph({ children: [ new TextRun("This is a simple demo "), new TextRun({ - text: "on how to " + text: "on how to ", }), new InsertedTextRun({ text: "mark a text as an insertion ", @@ -55,7 +68,7 @@ const paragraph = new Paragraph({ id: 1, author: "Firstname Lastname", date: "2020-10-06T09:00:00Z", - }) + }), ], }); @@ -92,7 +105,7 @@ doc.addSection({ }), new TextRun({ bold: true, - children: [ "\tuse Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1) ], + children: ["\tuse Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)], }), ], }), diff --git a/docs/usage/change-tracking.md b/docs/usage/change-tracking.md index 6f81e4d0d7..a5ca66ebb3 100644 --- a/docs/usage/change-tracking.md +++ b/docs/usage/change-tracking.md @@ -53,6 +53,9 @@ In addtion to marking text as inserted or deleted, change tracking can also be a ```ts import { Document } from "docx"; -const doc = new Document({}); -doc.Settings.addTrackRevisions() -``` \ No newline at end of file +const doc = new Document({ + features: { + trackRevisions: true, + }, +}); +``` diff --git a/src/file/core-properties/properties.ts b/src/file/core-properties/properties.ts index 96e9785175..ae9f227ad5 100644 --- a/src/file/core-properties/properties.ts +++ b/src/file/core-properties/properties.ts @@ -34,6 +34,9 @@ export interface IPropertiesOptions { readonly [key: string]: IInternalHyperlinkDefinition | IExternalHyperlinkDefinition; }; readonly background?: IDocumentBackgroundOptions; + readonly features?: { + readonly trackRevisions?: boolean; + }; } export class CoreProperties extends XmlComponent { diff --git a/src/file/file.ts b/src/file/file.ts index 15a4dc9739..1c655253de 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -170,6 +170,12 @@ export class File { this.hyperlinkCache = cache; } + + if (options.features) { + if (options.features.trackRevisions) { + this.settings.addTrackRevisions(); + } + } } public addSection({