Skip to content

Commit

Permalink
fix some bugs and pptx
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalic committed Sep 9, 2024
1 parent 73d2234 commit fec2141
Show file tree
Hide file tree
Showing 34 changed files with 834 additions and 456 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

name: deployment
on:
push:
branch: master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 14.x
cache: 'yarn'
- run: yarn
- name: build
run: |
yarn compile
yarn build
- name: publish
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
Binary file modified __tests__/files/loader.pptx
Binary file not shown.
42 changes: 42 additions & 0 deletions __tests__/loader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import zipDoc from "../src/document"
import openxml from "../src/openxml/document"
import pptx from "../src/openxml/pptx/document"
import docx4js from "../src"

describe("loader", function(){
Expand Down Expand Up @@ -78,5 +79,46 @@ describe("loader", function(){
it("can create", function(){
return docx4js.create().then(check)
})

it("can extract text from pptx",()=>{
return pptx.load(`${loader}.pptx`)
.then(pptx=>{
const slides=new Proxy([[[]]], {
get(target, key){
if(key==="current"){
return target[target.length-1]
}else if(key==="p"){
const slide=slides.current
return slide[slide.length-1]
}
return target[key]
}
})
pptx.render(function createElement(type,props,children){
switch(type){
case "slideLayout":
slides.current.splice(0,Number.MAX_SAFE_INTEGER,[])
break
case "slide":
slides.current.pop()
slides.push([[]])
break
case "p":
slides.current.push([])
break
case "t":
slides.p.push(children)
break
}
return {type,props,children}
})
slides.pop()
const content=slides.map((paragraphs,i)=>`slide #${i+1}:\n${paragraphs.map(a=>a.join("")).join("\n")}`).join("\n")
return content
}).then(parsed=>{
expect(parsed.indexOf("slide #1")).not.toBe(-1)
expect(parsed.indexOf("slide #2")).not.toBe(-1)
})
})
})
})
494 changes: 265 additions & 229 deletions dist/docx4js.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/cheerio-fn.js

Large diffs are not rendered by default.

36 changes: 23 additions & 13 deletions lib/document.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/openxml/document.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fec2141

Please sign in to comment.