pptxtojson 1.9.0 → 1.10.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/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/align.js +50 -0
- package/src/text.js +40 -12
package/package.json
CHANGED
package/src/align.js
CHANGED
|
@@ -96,4 +96,54 @@ export function getTextAutoFit(node, slideLayoutSpNode, slideMasterSpNode) {
|
|
|
96
96
|
if (masterCheck) return masterCheck.result
|
|
97
97
|
|
|
98
98
|
return null
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function getParagraphSpacing(pNode) {
|
|
102
|
+
if (!pNode) return null
|
|
103
|
+
|
|
104
|
+
const pPrNode = pNode['a:pPr']
|
|
105
|
+
if (!pPrNode) return null
|
|
106
|
+
|
|
107
|
+
const spacing = {}
|
|
108
|
+
|
|
109
|
+
const lnSpcNode = pPrNode['a:lnSpc']
|
|
110
|
+
if (lnSpcNode) {
|
|
111
|
+
const spcPct = getTextByPathList(lnSpcNode, ['a:spcPct', 'attrs', 'val'])
|
|
112
|
+
const spcPts = getTextByPathList(lnSpcNode, ['a:spcPts', 'attrs', 'val'])
|
|
113
|
+
|
|
114
|
+
if (spcPct) {
|
|
115
|
+
spacing.lineSpacing = parseInt(spcPct) / 1000 / 100
|
|
116
|
+
}
|
|
117
|
+
else if (spcPts) {
|
|
118
|
+
spacing.lineSpacing = parseInt(spcPts) / 100 + 'pt'
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const spcBefNode = pPrNode['a:spcBef']
|
|
123
|
+
if (spcBefNode) {
|
|
124
|
+
const spcPct = getTextByPathList(spcBefNode, ['a:spcPct', 'attrs', 'val'])
|
|
125
|
+
const spcPts = getTextByPathList(spcBefNode, ['a:spcPts', 'attrs', 'val'])
|
|
126
|
+
|
|
127
|
+
if (spcPct) {
|
|
128
|
+
spacing.spaceBefore = parseInt(spcPct) / 1000 + 'em'
|
|
129
|
+
}
|
|
130
|
+
else if (spcPts) {
|
|
131
|
+
spacing.spaceBefore = parseInt(spcPts) / 100 + 'pt'
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const spcAftNode = pPrNode['a:spcAft']
|
|
136
|
+
if (spcAftNode) {
|
|
137
|
+
const spcPct = getTextByPathList(spcAftNode, ['a:spcPct', 'attrs', 'val'])
|
|
138
|
+
const spcPts = getTextByPathList(spcAftNode, ['a:spcPts', 'attrs', 'val'])
|
|
139
|
+
|
|
140
|
+
if (spcPct) {
|
|
141
|
+
spacing.spaceAfter = parseInt(spcPct) / 1000 + 'em'
|
|
142
|
+
}
|
|
143
|
+
else if (spcPts) {
|
|
144
|
+
spacing.spaceAfter = parseInt(spcPts) / 100 + 'pt'
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return Object.keys(spacing).length > 0 ? spacing : null
|
|
99
149
|
}
|
package/src/text.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getHorizontalAlign } from './align'
|
|
1
|
+
import { getHorizontalAlign, getParagraphSpacing } from './align'
|
|
2
2
|
import { getTextByPathList } from './utils'
|
|
3
3
|
|
|
4
4
|
import {
|
|
@@ -24,7 +24,7 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, type, warpO
|
|
|
24
24
|
const pNode = textBodyNode['a:p']
|
|
25
25
|
const pNodes = pNode.constructor === Array ? pNode : [pNode]
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const listTypes = []
|
|
28
28
|
|
|
29
29
|
for (const pNode of pNodes) {
|
|
30
30
|
let rNode = pNode['a:r']
|
|
@@ -51,26 +51,41 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, type, warpO
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const align = getHorizontalAlign(pNode, spNode, type, warpObj)
|
|
54
|
+
const spacing = getParagraphSpacing(pNode)
|
|
55
|
+
|
|
56
|
+
let styleText = `text-align: ${align};`
|
|
57
|
+
if (spacing) {
|
|
58
|
+
if (spacing.lineSpacing) styleText += `line-height: ${spacing.lineSpacing};`
|
|
59
|
+
if (spacing.spaceBefore) styleText += `margin-top: ${spacing.spaceBefore};`
|
|
60
|
+
if (spacing.spaceAfter) styleText += `margin-bottom: ${spacing.spaceAfter};`
|
|
61
|
+
}
|
|
54
62
|
|
|
55
63
|
const listType = getListType(pNode)
|
|
64
|
+
const listLevel = getListLevel(pNode)
|
|
65
|
+
|
|
56
66
|
if (listType) {
|
|
57
|
-
|
|
67
|
+
while (listTypes.length > listLevel + 1) {
|
|
68
|
+
const closedListType = listTypes.pop()
|
|
69
|
+
text += `</${closedListType}>`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (listTypes[listLevel] === undefined) {
|
|
58
73
|
text += `<${listType}>`
|
|
59
|
-
|
|
74
|
+
listTypes[listLevel] = listType
|
|
60
75
|
}
|
|
61
|
-
else if (
|
|
62
|
-
text += `</${
|
|
76
|
+
else if (listTypes[listLevel] !== listType) {
|
|
77
|
+
text += `</${listTypes[listLevel]}>`
|
|
63
78
|
text += `<${listType}>`
|
|
64
|
-
|
|
79
|
+
listTypes[listLevel] = listType
|
|
65
80
|
}
|
|
66
|
-
text += `<li style="
|
|
81
|
+
text += `<li style="${styleText}">`
|
|
67
82
|
}
|
|
68
83
|
else {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
while (listTypes.length > 0) {
|
|
85
|
+
const closedListType = listTypes.pop()
|
|
86
|
+
text += `</${closedListType}>`
|
|
72
87
|
}
|
|
73
|
-
text += `<p style="
|
|
88
|
+
text += `<p style="${styleText}">`
|
|
74
89
|
}
|
|
75
90
|
|
|
76
91
|
if (!rNode) {
|
|
@@ -112,6 +127,10 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, type, warpO
|
|
|
112
127
|
if (listType) text += '</li>'
|
|
113
128
|
else text += '</p>'
|
|
114
129
|
}
|
|
130
|
+
while (listTypes.length > 0) {
|
|
131
|
+
const closedListType = listTypes.pop()
|
|
132
|
+
text += `</${closedListType}>`
|
|
133
|
+
}
|
|
115
134
|
return text
|
|
116
135
|
}
|
|
117
136
|
|
|
@@ -124,6 +143,15 @@ export function getListType(node) {
|
|
|
124
143
|
|
|
125
144
|
return ''
|
|
126
145
|
}
|
|
146
|
+
export function getListLevel(node) {
|
|
147
|
+
const pPrNode = node['a:pPr']
|
|
148
|
+
if (!pPrNode) return -1
|
|
149
|
+
|
|
150
|
+
const lvlNode = getTextByPathList(pPrNode, ['attrs', 'lvl'])
|
|
151
|
+
if (lvlNode !== undefined) return parseInt(lvlNode)
|
|
152
|
+
|
|
153
|
+
return 0
|
|
154
|
+
}
|
|
127
155
|
|
|
128
156
|
export function genSpanElement(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, type, warpObj) {
|
|
129
157
|
const { styleText, text, hasLink, linkURL } = getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, type, warpObj)
|