pptxtojson 2.0.3 → 2.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/src/text.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getHorizontalAlign, getParagraphSpacing } from './paragraph'
1
+ import { getHorizontalAlign, getParagraphSpacing, getParagraphIndent } from './paragraph'
2
2
  import { getTextByPathList } from './utils'
3
3
 
4
4
  import {
@@ -25,9 +25,9 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMaster
25
25
 
26
26
  let text = ''
27
27
 
28
- const pFontStyle = getTextByPathList(spNode, ['p:style', 'a:fontRef'])
29
- const slideMasterTextStyles = spNode && spNode['a:tcPr'] ? undefined : warpObj['slideMasterTextStyles']
30
- const defaultTextStyle = spNode && spNode['a:tcPr'] ? warpObj['defaultTextStyle'] : undefined
28
+ const pFontStyle = getTextByPathList(spNode, ['p:style', 'a:fontRef'])
29
+ const slideMasterTextStyles = spNode && spNode['a:tcPr'] ? undefined : warpObj['slideMasterTextStyles']
30
+ const defaultTextStyle = spNode && spNode['a:tcPr'] ? warpObj['defaultTextStyle'] : undefined
31
31
 
32
32
  const pNode = textBodyNode['a:p']
33
33
  const pNodes = pNode.constructor === Array ? pNode : [pNode]
@@ -59,7 +59,10 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMaster
59
59
  }
60
60
 
61
61
  const align = getHorizontalAlign(pNode, spNode, type, slideLayoutSpNode, slideMasterSpNode, warpObj)
62
- const spacing = getParagraphSpacing(pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, warpObj)
62
+ const spacing = getParagraphSpacing(pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, warpObj)
63
+ const indent = getParagraphIndent(pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, warpObj)
64
+ const listType = getListType(pNode)
65
+ const listLevel = getListLevel(pNode)
63
66
 
64
67
  let styleText = `text-align: ${align};`
65
68
  if (spacing) {
@@ -67,9 +70,10 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMaster
67
70
  if (spacing.spaceBefore) styleText += `margin-top: ${spacing.spaceBefore};`
68
71
  if (spacing.spaceAfter) styleText += `margin-bottom: ${spacing.spaceAfter};`
69
72
  }
70
-
71
- const listType = getListType(pNode)
72
- const listLevel = getListLevel(pNode)
73
+ if (indent) {
74
+ if (!listType && indent.marginLeft) styleText += `margin-left: ${indent.marginLeft};`
75
+ if (!listType && indent.textIndent) styleText += `text-indent: ${indent.textIndent};`
76
+ }
73
77
 
74
78
  if (listType) {
75
79
  while (listTypes.length > listLevel + 1) {
@@ -86,7 +90,7 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMaster
86
90
  text += `<${listType}>`
87
91
  listTypes[listLevel] = listType
88
92
  }
89
- text += `<li style="${styleText}">`
93
+ text += `<li><p style="${styleText}">`
90
94
  }
91
95
  else {
92
96
  while (listTypes.length > 0) {
@@ -97,14 +101,14 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMaster
97
101
  }
98
102
 
99
103
  if (!rNode) {
100
- text += genSpanElement(pNode, spNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj)
104
+ text += genSpanElement(pNode, spNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj)
101
105
  }
102
106
  else {
103
107
  let prevStyleInfo = null
104
108
  let accumulatedText = ''
105
109
 
106
110
  for (const rNodeItem of rNode) {
107
- const styleInfo = getSpanStyleInfo(rNodeItem, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj)
111
+ const styleInfo = getSpanStyleInfo(rNodeItem, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj)
108
112
 
109
113
  if (!prevStyleInfo || prevStyleInfo.styleText !== styleInfo.styleText || prevStyleInfo.hasLink !== styleInfo.hasLink || styleInfo.hasLink) {
110
114
  if (accumulatedText) {
@@ -132,7 +136,7 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMaster
132
136
  }
133
137
  }
134
138
 
135
- if (listType) text += '</li>'
139
+ if (listType) text += '</p></li>'
136
140
  else text += '</p>'
137
141
  }
138
142
  while (listTypes.length > 0) {
@@ -161,8 +165,8 @@ export function getListLevel(node) {
161
165
  return 0
162
166
  }
163
167
 
164
- export function genSpanElement(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj) {
165
- const { styleText, text, hasLink, linkURL } = getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj)
168
+ export function genSpanElement(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj) {
169
+ const { styleText, text, hasLink, linkURL } = getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj)
166
170
  const processedText = text.replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;').replace(/\s/g, '&nbsp;')
167
171
 
168
172
  if (hasLink) {
@@ -171,7 +175,7 @@ export function genSpanElement(node, pNode, textBodyNode, pFontStyle, slideLayou
171
175
  return `<span style="${styleText}">${processedText}</span>`
172
176
  }
173
177
 
174
- export function getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj) {
178
+ export function getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, defaultTextStyle, warpObj) {
175
179
  let lvl = 1
176
180
  const pPrNode = pNode['a:pPr']
177
181
  const lvlNode = getTextByPathList(pPrNode, ['attrs', 'lvl'])
@@ -183,7 +187,7 @@ export function getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLay
183
187
 
184
188
  let styleText = ''
185
189
  const fontColor = getFontColor(node, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl, pFontStyle, warpObj)
186
- const fontSize = getFontSize(node, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl, defaultTextStyle)
190
+ const fontSize = getFontSize(node, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl, defaultTextStyle)
187
191
  const fontType = getFontType(node, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl, warpObj)
188
192
  const fontBold = getFontBold(node, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl)
189
193
  const fontItalic = getFontItalic(node, pNode, textBodyNode, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles, lvl)
@@ -221,4 +225,4 @@ export function getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLay
221
225
  hasLink,
222
226
  linkURL: hasLink ? warpObj['slideResObj'][linkID]['target'] : null
223
227
  }
224
- }
228
+ }