node-pptx-templater 1.0.2 → 1.0.4
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/CHANGELOG.md +28 -3
- package/README.md +175 -327
- package/package.json +12 -3
- package/src/cli/commands/build.js +30 -31
- package/src/cli/commands/debug.js +23 -23
- package/src/cli/commands/extract.js +21 -21
- package/src/cli/commands/inspect.js +23 -23
- package/src/cli/commands/validate.js +17 -17
- package/src/cli/index.js +39 -36
- package/src/core/OutputWriter.js +79 -78
- package/src/core/PPTXTemplater.js +856 -273
- package/src/core/TemplateEngine.js +67 -71
- package/src/core/ValidationEngine.js +246 -0
- package/src/index.js +30 -17
- package/src/managers/ChartManager.js +195 -70
- package/src/managers/ContentTypesManager.js +49 -45
- package/src/managers/HyperlinkManager.js +146 -142
- package/src/managers/ImageManager.js +336 -0
- package/src/managers/MediaManager.js +62 -81
- package/src/managers/RelationshipManager.js +99 -95
- package/src/managers/ShapeManager.js +340 -0
- package/src/managers/SlideManager.js +408 -311
- package/src/managers/TableManager.js +979 -262
- package/src/managers/TextManager.js +197 -0
- package/src/managers/ZipManager.js +69 -69
- package/src/managers/charts/ChartCacheGenerator.js +75 -58
- package/src/managers/charts/ChartParser.js +9 -13
- package/src/managers/charts/ChartRelationshipManager.js +12 -10
- package/src/managers/charts/ChartWorkbookUpdater.js +59 -56
- package/src/parsers/XMLParser.js +47 -50
- package/src/templates/blankPptx.js +3 -2
- package/src/templates/slideTemplate.js +28 -34
- package/src/utils/contentTypesHelper.js +40 -54
- package/src/utils/errors.js +18 -18
- package/src/utils/idUtils.js +16 -14
- package/src/utils/logger.js +18 -16
- package/src/utils/relationshipUtils.js +19 -20
- package/src/utils/xmlUtils.js +26 -26
package/src/utils/xmlUtils.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* attempt automatic repairs for common PPTX corruption issues.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const { XMLParser } = require('../parsers/XMLParser.js')
|
|
8
|
+
const { XMLParser } = require('../parsers/XMLParser.js')
|
|
9
9
|
|
|
10
|
-
const parser = new XMLParser()
|
|
10
|
+
const parser = new XMLParser()
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Validates that an XML string is well-formed.
|
|
@@ -20,7 +20,7 @@ const parser = new XMLParser();
|
|
|
20
20
|
* if (!valid) console.error('XML error:', error);
|
|
21
21
|
*/
|
|
22
22
|
function validateXML(xmlString) {
|
|
23
|
-
return parser.validate(xmlString)
|
|
23
|
+
return parser.validate(xmlString)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -39,39 +39,39 @@ function validateXML(xmlString) {
|
|
|
39
39
|
* if (repaired) console.log('Repaired:', changes);
|
|
40
40
|
*/
|
|
41
41
|
function repairXML(xmlString) {
|
|
42
|
-
const changes = []
|
|
43
|
-
let xml = xmlString
|
|
42
|
+
const changes = []
|
|
43
|
+
let xml = xmlString
|
|
44
44
|
|
|
45
45
|
// Fix 1: Remove invalid XML control characters
|
|
46
|
-
const before = xml
|
|
47
|
-
xml = xml.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '')
|
|
48
|
-
if (xml !== before) changes.push('Removed invalid control characters')
|
|
46
|
+
const before = xml
|
|
47
|
+
xml = xml.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '')
|
|
48
|
+
if (xml !== before) changes.push('Removed invalid control characters')
|
|
49
49
|
|
|
50
50
|
// Fix 2: Fix unescaped ampersands in text content (not in entities)
|
|
51
51
|
// Match & not followed by valid entity patterns
|
|
52
|
-
const fixedAmp = xml.replace(/&(?!amp;|lt;|gt;|quot;|apos;|#\d+;|#x[0-9a-fA-F]+;)/g, '&')
|
|
52
|
+
const fixedAmp = xml.replace(/&(?!amp;|lt;|gt;|quot;|apos;|#\d+;|#x[0-9a-fA-F]+;)/g, '&')
|
|
53
53
|
if (fixedAmp !== xml) {
|
|
54
|
-
xml = fixedAmp
|
|
55
|
-
changes.push('Escaped unescaped ampersands')
|
|
54
|
+
xml = fixedAmp
|
|
55
|
+
changes.push('Escaped unescaped ampersands')
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// Fix 3: Replace null bytes
|
|
59
59
|
if (xml.includes('\x00')) {
|
|
60
|
-
xml = xml.replace(/\x00/g, '')
|
|
61
|
-
changes.push('Removed null bytes')
|
|
60
|
+
xml = xml.replace(/\x00/g, '')
|
|
61
|
+
changes.push('Removed null bytes')
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// Fix 4: Ensure XML declaration is present
|
|
65
65
|
if (!xml.trimStart().startsWith('<?xml')) {
|
|
66
|
-
xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' + xml
|
|
67
|
-
changes.push('Added missing XML declaration')
|
|
66
|
+
xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' + xml
|
|
67
|
+
changes.push('Added missing XML declaration')
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
return {
|
|
71
71
|
xml,
|
|
72
72
|
repaired: changes.length > 0,
|
|
73
73
|
changes,
|
|
74
|
-
}
|
|
74
|
+
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -82,7 +82,7 @@ function repairXML(xmlString) {
|
|
|
82
82
|
* @returns {boolean}
|
|
83
83
|
*/
|
|
84
84
|
function xmlContainsElement(xmlString, elementName) {
|
|
85
|
-
return xmlString.includes(`<${elementName}`) || xmlString.includes(`<${elementName}>`)
|
|
85
|
+
return xmlString.includes(`<${elementName}`) || xmlString.includes(`<${elementName}>`)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
@@ -93,8 +93,8 @@ function xmlContainsElement(xmlString, elementName) {
|
|
|
93
93
|
* @returns {number}
|
|
94
94
|
*/
|
|
95
95
|
function countElements(xmlString, elementName) {
|
|
96
|
-
const pattern = new RegExp(`<${elementName}[\\s>/]`, 'g')
|
|
97
|
-
return (xmlString.match(pattern) || []).length
|
|
96
|
+
const pattern = new RegExp(`<${elementName}[\\s>/]`, 'g')
|
|
97
|
+
return (xmlString.match(pattern) || []).length
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/**
|
|
@@ -105,13 +105,13 @@ function countElements(xmlString, elementName) {
|
|
|
105
105
|
* @returns {string[]} Array of attribute values found.
|
|
106
106
|
*/
|
|
107
107
|
function extractAttributeValues(xmlString, attrName) {
|
|
108
|
-
const pattern = new RegExp(`${attrName.replace(':', '\\:')}="([^"]*)"`, 'g')
|
|
109
|
-
const values = []
|
|
110
|
-
let match
|
|
108
|
+
const pattern = new RegExp(`${attrName.replace(':', '\\:')}="([^"]*)"`, 'g')
|
|
109
|
+
const values = []
|
|
110
|
+
let match
|
|
111
111
|
while ((match = pattern.exec(xmlString)) !== null) {
|
|
112
|
-
values.push(match[1])
|
|
112
|
+
values.push(match[1])
|
|
113
113
|
}
|
|
114
|
-
return values
|
|
114
|
+
return values
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
module.exports = {
|
|
@@ -119,5 +119,5 @@ module.exports = {
|
|
|
119
119
|
repairXML,
|
|
120
120
|
xmlContainsElement,
|
|
121
121
|
countElements,
|
|
122
|
-
extractAttributeValues
|
|
123
|
-
}
|
|
122
|
+
extractAttributeValues,
|
|
123
|
+
}
|