50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import {
|
|
Document,
|
|
Paragraph,
|
|
TextRun,
|
|
DeletedTextRun,
|
|
InsertedTextRun,
|
|
LevelFormat,
|
|
LevelSuffix,
|
|
AlignmentType,
|
|
Packer
|
|
} from 'docx';
|
|
import JSZip from 'jszip';
|
|
import fs from 'fs';
|
|
|
|
const doc = new Document({
|
|
features: { trackRevisions: true },
|
|
sections: [{
|
|
children: [new Paragraph({
|
|
children: [
|
|
new DeletedTextRun({
|
|
id: 1,
|
|
author: 'Editor',
|
|
date: new Date().toISOString(),
|
|
text: 'David Harvey ',
|
|
font: 'Charis SIL',
|
|
size: 15
|
|
}),
|
|
new InsertedTextRun({
|
|
id: 2,
|
|
author: 'Editor',
|
|
date: new Date().toISOString(),
|
|
text: 'Harvey D ',
|
|
font: 'Charis SIL',
|
|
size: 15
|
|
}),
|
|
new TextRun('Contemporary Nursing Knowledge.')
|
|
]
|
|
})]
|
|
}]
|
|
});
|
|
|
|
const buf = await Packer.toBuffer(doc);
|
|
fs.writeFileSync('test-ref-revision.docx', buf);
|
|
const zip = await JSZip.loadAsync(buf);
|
|
const docXml = await zip.file('word/document.xml').async('string');
|
|
const settingsXml = await zip.file('word/settings.xml').async('string');
|
|
console.log('has w:ins:', docXml.includes('<w:ins'));
|
|
console.log('has w:del:', docXml.includes('<w:del'));
|
|
console.log('trackRevisions:', settingsXml.includes('trackRevisions'));
|