feat: 导出 pptx 文件支持文本项目符号(#95)

This commit is contained in:
pipipi-pikachu 2022-04-14 21:14:39 +08:00
parent 7f5dee88b6
commit bc8e5a97c9

View File

@ -82,7 +82,7 @@ export default () => {
const slices: pptxgen.TextProps[] = [] const slices: pptxgen.TextProps[] = []
const parse = (obj: AST[], baseStyleObj = {}) => { const parse = (obj: AST[], baseStyleObj = {}) => {
for (const item of obj) { for (const item of obj) {
if ('tagName' in item && ['div', 'ul', 'li', 'p'].includes(item.tagName) && slices.length) { if ('tagName' in item && ['div', 'li', 'p'].includes(item.tagName) && slices.length) {
const lastSlice = slices[slices.length - 1] const lastSlice = slices[slices.length - 1]
if (!lastSlice.options) lastSlice.options = {} if (!lastSlice.options) lastSlice.options = {}
lastSlice.options.breakLine = true lastSlice.options.breakLine = true
@ -99,6 +99,11 @@ export default () => {
} }
} }
if ('tagName' in item) {
if (item.tagName === 'ul') styleObj['list-type'] = 'ul'
if (item.tagName === 'ol') styleObj['list-type'] = 'ol'
}
if ('tagName' in item) { if ('tagName' in item) {
if (item.tagName === 'em') { if (item.tagName === 'em') {
styleObj['font-style'] = 'italic' styleObj['font-style'] = 'italic'
@ -169,6 +174,13 @@ export default () => {
slices.push({ text, options }) slices.push({ text, options })
} }
else if ('children' in item) parse(item.children, styleObj) else if ('children' in item) parse(item.children, styleObj)
if ('tagName' in item && item.tagName === 'li') {
const slice = slices[slices.length - 1]
if (!slice.options) slice.options = {}
if (styleObj['list-type'] === 'ol') slice.options.bullet = { type: 'number', indent: 20 * 0.75 }
if (styleObj['list-type'] === 'ul') slice.options.bullet = { indent: 20 * 0.75 }
}
} }
} }
parse(ast) parse(ast)