officeparser 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -18
- package/dist/OfficeGenerator.d.ts +1 -1
- package/dist/OfficeGenerator.js +16 -7
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +12 -3
- package/dist/defaults.js +11 -0
- package/dist/generators/BaseGenerator.d.ts +3 -3
- package/dist/generators/ChunkingGenerator.js +8 -1
- package/dist/generators/CsvGenerator.d.ts +1 -1
- package/dist/generators/HtmlGenerator.d.ts +2 -1
- package/dist/generators/HtmlGenerator.js +462 -40
- package/dist/generators/MarkdownGenerator.d.ts +1 -1
- package/dist/generators/MarkdownGenerator.js +3 -1
- package/dist/generators/PdfGenerator.d.ts +1 -1
- package/dist/generators/PdfGenerator.js +0 -6
- package/dist/generators/RtfGenerator.d.ts +2 -1
- package/dist/generators/RtfGenerator.js +43 -6
- package/dist/generators/TextGenerator.d.ts +1 -1
- package/dist/officeparser.browser.d.ts +259 -52
- package/dist/officeparser.browser.iife.js +380 -93
- package/dist/officeparser.browser.mjs +380 -93
- package/dist/parsers/CsvParser.js +1 -1
- package/dist/parsers/ExcelParser.js +63 -19
- package/dist/parsers/HtmlParser.js +10 -1
- package/dist/parsers/MarkdownParser.js +13 -10
- package/dist/parsers/OpenOfficeParser.js +57 -34
- package/dist/parsers/PdfParser.js +23 -1
- package/dist/parsers/PowerPointParser.js +164 -40
- package/dist/parsers/RtfParser.js +28 -24
- package/dist/parsers/WordParser.js +154 -11
- package/dist/sbom.cdx.json +100 -100
- package/dist/types.d.ts +265 -52
- package/dist/types.js +2 -0
- package/dist/utils/astUtils.d.ts +2 -2
- package/dist/utils/astUtils.js +2 -1
- package/dist/utils/configUtils.d.ts +5 -0
- package/dist/utils/configUtils.js +55 -1
- package/dist/utils/errorUtils.js +2 -1
- package/dist/utils/xmlUtils.d.ts +9 -0
- package/dist/utils/xmlUtils.js +53 -1
- package/package.json +1 -1
package/dist/utils/xmlUtils.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* @module xmlUtils
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.decodeXmlEntities = exports.parseOOXMLCustomProperties = exports.parseOfficeMetadata = exports.getDirectChildren = exports.getAttribute = exports.getFirstElementByTagName = exports.getRawContent = exports.getSourceSubstring = exports.serializeXml = exports.getElementsByTagName = exports.parseXmlString = exports.isElement = void 0;
|
|
14
|
+
exports.decodeXmlEntities = exports.parseOOXMLAppProperties = exports.parseOOXMLCustomProperties = exports.parseOfficeMetadata = exports.getDirectChildren = exports.getAttribute = exports.getFirstElementByTagName = exports.getRawContent = exports.getSourceSubstring = exports.serializeXml = exports.getElementsByTagName = exports.parseXmlString = exports.isElement = void 0;
|
|
15
15
|
const xmldom_1 = require("@xmldom/xmldom");
|
|
16
16
|
const dateUtils_js_1 = require("./dateUtils.js");
|
|
17
17
|
/**
|
|
@@ -221,6 +221,13 @@ const parseOfficeMetadata = (xmlContent) => {
|
|
|
221
221
|
// Check for OOXML Core Properties
|
|
222
222
|
const coreProperties = (0, exports.getElementsByTagName)(xml, "cp:coreProperties")[0];
|
|
223
223
|
if (coreProperties) {
|
|
224
|
+
metadata.nativeProperties = {};
|
|
225
|
+
for (let i = 0; i < coreProperties.childNodes.length; i++) {
|
|
226
|
+
const child = coreProperties.childNodes[i];
|
|
227
|
+
if ((0, exports.isElement)(child)) {
|
|
228
|
+
metadata.nativeProperties[child.tagName] = child.textContent;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
224
231
|
// Step 3: Extract title (Dublin Core element)
|
|
225
232
|
const title = (0, exports.getElementsByTagName)(coreProperties, "dc:title")[0];
|
|
226
233
|
if (title && title.textContent)
|
|
@@ -248,11 +255,21 @@ const parseOfficeMetadata = (xmlContent) => {
|
|
|
248
255
|
const subject = (0, exports.getElementsByTagName)(coreProperties, "dc:subject")[0];
|
|
249
256
|
if (subject && subject.textContent)
|
|
250
257
|
metadata.subject = subject.textContent;
|
|
258
|
+
const keywords = (0, exports.getElementsByTagName)(coreProperties, "cp:keywords")[0];
|
|
259
|
+
if (keywords && keywords.textContent)
|
|
260
|
+
metadata.keywords = keywords.textContent;
|
|
251
261
|
return metadata;
|
|
252
262
|
}
|
|
253
263
|
// Check for ODF Meta
|
|
254
264
|
const officeMeta = (0, exports.getElementsByTagName)(xml, "office:meta")[0];
|
|
255
265
|
if (officeMeta) {
|
|
266
|
+
metadata.nativeProperties = {};
|
|
267
|
+
for (let i = 0; i < officeMeta.childNodes.length; i++) {
|
|
268
|
+
const child = officeMeta.childNodes[i];
|
|
269
|
+
if ((0, exports.isElement)(child)) {
|
|
270
|
+
metadata.nativeProperties[child.tagName] = child.textContent;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
256
273
|
const title = (0, exports.getElementsByTagName)(officeMeta, "dc:title")[0];
|
|
257
274
|
if (title && title.textContent)
|
|
258
275
|
metadata.title = title.textContent;
|
|
@@ -265,6 +282,10 @@ const parseOfficeMetadata = (xmlContent) => {
|
|
|
265
282
|
const subject = (0, exports.getElementsByTagName)(officeMeta, "dc:subject")[0];
|
|
266
283
|
if (subject && subject.textContent)
|
|
267
284
|
metadata.subject = subject.textContent;
|
|
285
|
+
const keywordElements = (0, exports.getElementsByTagName)(officeMeta, "meta:keyword");
|
|
286
|
+
if (keywordElements.length > 0) {
|
|
287
|
+
metadata.keywords = keywordElements.map(k => k.textContent).filter(Boolean).join(', ');
|
|
288
|
+
}
|
|
268
289
|
const created = (0, exports.getElementsByTagName)(officeMeta, "meta:creation-date")[0];
|
|
269
290
|
if (created && created.textContent)
|
|
270
291
|
metadata.created = (0, dateUtils_js_1.parseOfficeDate)(created.textContent);
|
|
@@ -375,6 +396,37 @@ const parseOOXMLCustomProperties = (xmlContent) => {
|
|
|
375
396
|
return result;
|
|
376
397
|
};
|
|
377
398
|
exports.parseOOXMLCustomProperties = parseOOXMLCustomProperties;
|
|
399
|
+
/**
|
|
400
|
+
* Parses OOXML application properties from `docProps/app.xml`.
|
|
401
|
+
*
|
|
402
|
+
* Application properties contain document statistics and application settings.
|
|
403
|
+
*
|
|
404
|
+
* @param xmlContent - Raw XML string from `docProps/app.xml`
|
|
405
|
+
* @returns A record of property name -> typed value
|
|
406
|
+
*/
|
|
407
|
+
const parseOOXMLAppProperties = (xmlContent) => {
|
|
408
|
+
const xml = (0, exports.parseXmlString)(xmlContent);
|
|
409
|
+
const result = {};
|
|
410
|
+
const appProperties = (0, exports.getElementsByTagName)(xml, "Properties")[0];
|
|
411
|
+
if (appProperties) {
|
|
412
|
+
for (let i = 0; i < appProperties.childNodes.length; i++) {
|
|
413
|
+
const child = appProperties.childNodes[i];
|
|
414
|
+
if ((0, exports.isElement)(child)) {
|
|
415
|
+
const text = child.textContent || '';
|
|
416
|
+
if (text.toLowerCase() === 'true')
|
|
417
|
+
result[child.tagName] = true;
|
|
418
|
+
else if (text.toLowerCase() === 'false')
|
|
419
|
+
result[child.tagName] = false;
|
|
420
|
+
else if (!isNaN(Number(text)) && text.trim() !== '')
|
|
421
|
+
result[child.tagName] = Number(text);
|
|
422
|
+
else
|
|
423
|
+
result[child.tagName] = text;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return result;
|
|
428
|
+
};
|
|
429
|
+
exports.parseOOXMLAppProperties = parseOOXMLAppProperties;
|
|
378
430
|
/**
|
|
379
431
|
* Decodes XML entities (standard named entities, decimal, and hexadecimal entities) in a string.
|
|
380
432
|
* Useful when parsing content with regular expressions instead of a full DOM parser.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "officeparser",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "A robust, strictly-typed Node.js and Browser library for parsing office files (.docx, .pptx, .xlsx, .odt, .odp, .ods, .pdf, .rtf, .csv, .md, .html) and generating high-fidelity outputs in Markdown, HTML, CSV, RTF, and RAG-focused chunks.",
|
|
5
5
|
"funding": "https://github.com/sponsors/harshankur",
|
|
6
6
|
"main": "dist/index.js",
|