diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 52fe4453db..13b09ebd87 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -34,5 +34,5 @@ Uses **Vitest**. Tests are co-located with source files as `*.spec.ts`. ## Running Demos ```bash -npm run run-ts -- ./demo/.ts +npm run run-ts -- ./demo//.ts ``` diff --git a/.github/workflows/demos.yml b/.github/workflows/demos.yml index aef3337fa2..effd600ec4 100644 --- a/.github/workflows/demos.yml +++ b/.github/workflows/demos.yml @@ -33,7 +33,7 @@ jobs: - name: Run and validate the demos shell: bash run: | - for demo in $(ls demo/[0-9]*.ts | sort -V | awk -v n=${{ strategy.job-total }} -v i=${{ strategy.job-index }} 'NR % n == i'); do + for demo in $(find demo -mindepth 2 -name "*.ts" -not -path "demo/assets/*" | sort | awk -v n=${{ strategy.job-total }} -v i=${{ strategy.job-index }} 'NR % n == i'); do echo "::group::$demo" rm -rf ./*.docx embeddings npm run --silent run-ts -- "$demo" diff --git a/CLAUDE.md b/CLAUDE.md index 3dcfd4f8ae..3c3f247c6d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -27,5 +27,5 @@ TypeScript library for generating .docx files. Declarative API, works in Node.js ## Running Demos ```bash -npm run run-ts -- ./demo/.ts +npm run run-ts -- ./demo//.ts ``` diff --git a/demo/images/cat.jpg b/demo/assets/images/cat.jpg similarity index 100% rename from demo/images/cat.jpg rename to demo/assets/images/cat.jpg diff --git a/demo/images/dog.png b/demo/assets/images/dog.png similarity index 100% rename from demo/images/dog.png rename to demo/assets/images/dog.png diff --git a/demo/images/image1.jpeg b/demo/assets/images/image1.jpeg similarity index 100% rename from demo/images/image1.jpeg rename to demo/assets/images/image1.jpeg diff --git a/demo/images/linux-png.png b/demo/assets/images/linux-png.png similarity index 100% rename from demo/images/linux-png.png rename to demo/assets/images/linux-png.png diff --git a/demo/images/linux-svg.svg b/demo/assets/images/linux-svg.svg similarity index 100% rename from demo/images/linux-svg.svg rename to demo/assets/images/linux-svg.svg diff --git a/demo/images/parrots.bmp b/demo/assets/images/parrots.bmp similarity index 100% rename from demo/images/parrots.bmp rename to demo/assets/images/parrots.bmp diff --git a/demo/images/pizza.gif b/demo/assets/images/pizza.gif similarity index 100% rename from demo/images/pizza.gif rename to demo/assets/images/pizza.gif diff --git a/demo/dotx/template.dotx b/demo/assets/template.dotx similarity index 100% rename from demo/dotx/template.dotx rename to demo/assets/template.dotx diff --git a/demo/124-chart-data-in-templates.ts b/demo/charts/chart-data-in-templates.ts similarity index 100% rename from demo/124-chart-data-in-templates.ts rename to demo/charts/chart-data-in-templates.ts diff --git a/demo/122-chart-options.ts b/demo/charts/chart-options.ts similarity index 100% rename from demo/122-chart-options.ts rename to demo/charts/chart-options.ts diff --git a/demo/123-charts-in-templates.ts b/demo/charts/charts-in-templates.ts similarity index 100% rename from demo/123-charts-in-templates.ts rename to demo/charts/charts-in-templates.ts diff --git a/demo/121-charts.ts b/demo/charts/charts.ts similarity index 100% rename from demo/121-charts.ts rename to demo/charts/charts.ts diff --git a/demo/125-more-charts.ts b/demo/charts/more-charts.ts similarity index 100% rename from demo/125-more-charts.ts rename to demo/charts/more-charts.ts diff --git a/demo/101-comment-replies.ts b/demo/comments/comment-replies.ts similarity index 97% rename from demo/101-comment-replies.ts rename to demo/comments/comment-replies.ts index 738936ee72..479ad7014f 100644 --- a/demo/101-comment-replies.ts +++ b/demo/comments/comment-replies.ts @@ -1,5 +1,5 @@ /** - * Demo 101: Comment replies (threading) and resolved comments. + * Comment replies (threading) and resolved comments. * * Shows two comment threads: one active with replies, one resolved. * See docs/usage/comments.md for full documentation. diff --git a/demo/73-comments.ts b/demo/comments/comments.ts similarity index 98% rename from demo/73-comments.ts rename to demo/comments/comments.ts index db21825f59..24bd0a57d7 100644 --- a/demo/73-comments.ts +++ b/demo/comments/comments.ts @@ -22,7 +22,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/cat.jpg"), + data: fs.readFileSync("./demo/assets/images/cat.jpg"), transformation: { width: 100, height: 100, diff --git a/demo/56-background-color.ts b/demo/document-settings/background-color.ts similarity index 100% rename from demo/56-background-color.ts rename to demo/document-settings/background-color.ts diff --git a/demo/76-compatibility.ts b/demo/document-settings/compatibility-options.ts similarity index 100% rename from demo/76-compatibility.ts rename to demo/document-settings/compatibility-options.ts diff --git a/demo/54-custom-properties.ts b/demo/document-settings/custom-properties.ts similarity index 100% rename from demo/54-custom-properties.ts rename to demo/document-settings/custom-properties.ts diff --git a/demo/19-export-to-base64.ts b/demo/exporting/base64-string.ts similarity index 100% rename from demo/19-export-to-base64.ts rename to demo/exporting/base64-string.ts diff --git a/demo/browser-demo.html b/demo/exporting/browser.html similarity index 95% rename from demo/browser-demo.html rename to demo/exporting/browser.html index f106c1fe12..5794704349 100644 --- a/demo/browser-demo.html +++ b/demo/exporting/browser.html @@ -1,9 +1,9 @@ - + - + diff --git a/demo/74-nodejs-stream.ts b/demo/exporting/node-stream.ts similarity index 100% rename from demo/74-nodejs-stream.ts rename to demo/exporting/node-stream.ts diff --git a/demo/66-fields.ts b/demo/fields/fields.ts similarity index 100% rename from demo/66-fields.ts rename to demo/fields/fields.ts diff --git a/demo/33-sequential-captions.ts b/demo/fields/sequential-captions.ts similarity index 100% rename from demo/33-sequential-captions.ts rename to demo/fields/sequential-captions.ts diff --git a/demo/28-table-of-contents.ts b/demo/fields/table-of-contents.ts similarity index 100% rename from demo/28-table-of-contents.ts rename to demo/fields/table-of-contents.ts diff --git a/demo/97-endnotes.ts b/demo/footnotes-and-endnotes/endnotes.ts similarity index 100% rename from demo/97-endnotes.ts rename to demo/footnotes-and-endnotes/endnotes.ts diff --git a/demo/17-footnotes.ts b/demo/footnotes-and-endnotes/footnotes.ts similarity index 98% rename from demo/17-footnotes.ts rename to demo/footnotes-and-endnotes/footnotes.ts index ddc528bcb3..91a98d769f 100644 --- a/demo/17-footnotes.ts +++ b/demo/footnotes-and-endnotes/footnotes.ts @@ -68,7 +68,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/cat.jpg"), + data: fs.readFileSync("./demo/assets/images/cat.jpg"), transformation: { width: 100, height: 100, diff --git a/demo/1-basic.ts b/demo/getting-started/basic-document.ts similarity index 100% rename from demo/1-basic.ts rename to demo/getting-started/basic-document.ts diff --git a/demo/10-my-cv.ts b/demo/getting-started/cv.ts similarity index 100% rename from demo/10-my-cv.ts rename to demo/getting-started/cv.ts diff --git a/demo/50-readme-demo.ts b/demo/getting-started/readme-example.ts similarity index 95% rename from demo/50-readme-demo.ts rename to demo/getting-started/readme-example.ts index 8090d936c6..dcdae91217 100644 --- a/demo/50-readme-demo.ts +++ b/demo/getting-started/readme-example.ts @@ -12,7 +12,7 @@ const table = new Table({ new Paragraph({ children: [ new ImageRun({ - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), type: "jpg", transformation: { width: 100, @@ -50,7 +50,7 @@ const table = new Table({ new Paragraph({ children: [ new ImageRun({ - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), type: "jpg", transformation: { width: 100, @@ -78,7 +78,7 @@ const doc = new Document({ new Paragraph({ children: [ new ImageRun({ - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), type: "gif", transformation: { width: 100, diff --git a/demo/81-continuous-header.ts b/demo/headers-and-footers/continuous-header.ts similarity index 100% rename from demo/81-continuous-header.ts rename to demo/headers-and-footers/continuous-header.ts diff --git a/demo/59-header-footer-margins.ts b/demo/headers-and-footers/header-and-footer-margins.ts similarity index 100% rename from demo/59-header-footer-margins.ts rename to demo/headers-and-footers/header-and-footer-margins.ts diff --git a/demo/8-header-footer.ts b/demo/headers-and-footers/header-and-footer.ts similarity index 100% rename from demo/8-header-footer.ts rename to demo/headers-and-footers/header-and-footer.ts diff --git a/demo/82-new-headers-new-section.ts b/demo/headers-and-footers/new-headers-in-new-section.ts similarity index 100% rename from demo/82-new-headers-new-section.ts rename to demo/headers-and-footers/new-headers-in-new-section.ts diff --git a/demo/63-odd-even-header-footer.ts b/demo/headers-and-footers/odd-and-even-headers-and-footers.ts similarity index 100% rename from demo/63-odd-even-header-footer.ts rename to demo/headers-and-footers/odd-and-even-headers-and-footers.ts diff --git a/demo/23-base64-images.ts b/demo/images/base64-images.ts similarity index 93% rename from demo/23-base64-images.ts rename to demo/images/base64-images.ts index f88746fe3d..f70a0b57b8 100644 --- a/demo/23-base64-images.ts +++ b/demo/images/base64-images.ts @@ -14,7 +14,7 @@ const doc = new Document({ new TextRun("Hello World"), new ImageRun({ type: "bmp", - data: fs.readFileSync("./demo/images/parrots.bmp"), + data: fs.readFileSync("./demo/assets/images/parrots.bmp"), transformation: { width: 100, height: 100, @@ -26,7 +26,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100, @@ -38,7 +38,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "png", - data: fs.readFileSync("./demo/images/dog.png"), + data: fs.readFileSync("./demo/assets/images/dog.png"), transformation: { width: 100, height: 100, @@ -50,7 +50,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/cat.jpg"), + data: fs.readFileSync("./demo/assets/images/cat.jpg"), transformation: { width: 100, height: 100, @@ -62,7 +62,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "bmp", - data: fs.readFileSync("./demo/images/parrots.bmp"), + data: fs.readFileSync("./demo/assets/images/parrots.bmp"), transformation: { width: 100, height: 100, diff --git a/demo/18-image-from-buffer.ts b/demo/images/image-from-buffer.ts similarity index 100% rename from demo/18-image-from-buffer.ts rename to demo/images/image-from-buffer.ts diff --git a/demo/36-image-to-table-cell.ts b/demo/images/image-in-header-table-cell.ts similarity index 98% rename from demo/36-image-to-table-cell.ts rename to demo/images/image-in-header-table-cell.ts index 7ad49c57b8..f20ba5d323 100644 --- a/demo/36-image-to-table-cell.ts +++ b/demo/images/image-in-header-table-cell.ts @@ -32,7 +32,7 @@ const table = new Table({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100, diff --git a/demo/43-images-to-table-cell-2.ts b/demo/images/image-in-merged-table-cell.ts similarity index 99% rename from demo/43-images-to-table-cell-2.ts rename to demo/images/image-in-merged-table-cell.ts index 88f451f963..0e0f6c585e 100644 --- a/demo/43-images-to-table-cell-2.ts +++ b/demo/images/image-in-merged-table-cell.ts @@ -51,7 +51,7 @@ const table = new Table({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100, diff --git a/demo/24-images-to-table-cell.ts b/demo/images/image-in-table-cell.ts similarity index 98% rename from demo/24-images-to-table-cell.ts rename to demo/images/image-in-table-cell.ts index de6b9b167f..2738b49343 100644 --- a/demo/24-images-to-table-cell.ts +++ b/demo/images/image-in-table-cell.ts @@ -36,7 +36,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100, diff --git a/demo/114-image-links.ts b/demo/images/image-links.ts similarity index 90% rename from demo/114-image-links.ts rename to demo/images/image-links.ts index 6d17749673..a0e9b56200 100644 --- a/demo/114-image-links.ts +++ b/demo/images/image-links.ts @@ -13,7 +13,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "bmp", - data: fs.readFileSync("./demo/images/parrots.bmp"), + data: fs.readFileSync("./demo/assets/images/parrots.bmp"), transformation: { width: 200, height: 150 }, altText: { name: "Parrots", description: "Two parrots on a branch", title: "Parrots" }, link: "https://en.wikipedia.org/wiki/Parrot", @@ -25,7 +25,7 @@ const doc = new Document({ new TextRun("A decorative image, which screen readers skip: "), new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 40, height: 40 }, decorative: true, }), @@ -36,7 +36,7 @@ const doc = new Document({ new TextRun("A floating image can have a link too."), new ImageRun({ type: "png", - data: fs.readFileSync("./demo/images/dog.png"), + data: fs.readFileSync("./demo/assets/images/dog.png"), transformation: { width: 100, height: 100 }, floating: { horizontalPosition: { relative: HorizontalPositionRelativeFrom.PAGE, offset: 5000000 }, diff --git a/demo/9-images-in-header-and-footer.ts b/demo/images/images-in-header-and-footer.ts similarity index 96% rename from demo/9-images-in-header-and-footer.ts rename to demo/images/images-in-header-and-footer.ts index e9cf960404..06fd2dc01d 100644 --- a/demo/9-images-in-header-and-footer.ts +++ b/demo/images/images-in-header-and-footer.ts @@ -13,7 +13,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 100, height: 100, @@ -31,7 +31,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 100, height: 100, diff --git a/demo/5-images.ts b/demo/images/images.ts similarity index 88% rename from demo/5-images.ts rename to demo/images/images.ts index 7953b939cd..d23d8897ad 100644 --- a/demo/5-images.ts +++ b/demo/images/images.ts @@ -22,7 +22,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100, @@ -39,7 +39,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "png", - data: fs.readFileSync("./demo/images/dog.png").toString("base64"), + data: fs.readFileSync("./demo/assets/images/dog.png").toString("base64"), transformation: { width: 100, height: 100, @@ -56,7 +56,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/cat.jpg"), + data: fs.readFileSync("./demo/assets/images/cat.jpg"), transformation: { width: 100, height: 100, @@ -77,7 +77,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "bmp", - data: fs.readFileSync("./demo/images/parrots.bmp"), + data: fs.readFileSync("./demo/assets/images/parrots.bmp"), transformation: { width: 150, height: 150, @@ -93,7 +93,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 200, height: 200, @@ -109,7 +109,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 200, height: 200, @@ -131,7 +131,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/cat.jpg"), + data: fs.readFileSync("./demo/assets/images/cat.jpg"), transformation: { width: 200, height: 200, @@ -154,14 +154,14 @@ const doc = new Document({ children: [ new ImageRun({ type: "svg", - data: fs.readFileSync("./demo/images/linux-svg.svg"), + data: fs.readFileSync("./demo/assets/images/linux-svg.svg"), transformation: { width: 200, height: 200, }, fallback: { type: "png", - data: fs.readFileSync("./demo/images/linux-png.png"), + data: fs.readFileSync("./demo/assets/images/linux-png.png"), }, }), ], diff --git a/demo/12-scaling-images.ts b/demo/images/scaling-images.ts similarity index 84% rename from demo/12-scaling-images.ts rename to demo/images/scaling-images.ts index 00afc9f99d..269387b6d0 100644 --- a/demo/12-scaling-images.ts +++ b/demo/images/scaling-images.ts @@ -12,7 +12,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 50, height: 50, @@ -24,7 +24,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 100, height: 100, @@ -36,7 +36,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 250, height: 250, @@ -48,7 +48,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 400, height: 400, diff --git a/demo/37-images-to-header-and-footer.ts b/demo/images/several-images-in-header.ts similarity index 95% rename from demo/37-images-to-header-and-footer.ts rename to demo/images/several-images-in-header.ts index 906966f601..5493e875ea 100644 --- a/demo/37-images-to-header-and-footer.ts +++ b/demo/images/several-images-in-header.ts @@ -13,7 +13,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100, @@ -25,7 +25,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 100, height: 100, @@ -37,7 +37,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100, diff --git a/demo/38-text-wrapping.ts b/demo/images/text-wrapping.ts similarity index 97% rename from demo/38-text-wrapping.ts rename to demo/images/text-wrapping.ts index 8bf6ea6c66..d2bf053490 100644 --- a/demo/38-text-wrapping.ts +++ b/demo/images/text-wrapping.ts @@ -21,7 +21,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 200, height: 200, diff --git a/demo/index.ts b/demo/index.ts index 9b1456d01a..e0d6711c3d 100644 --- a/demo/index.ts +++ b/demo/index.ts @@ -1,68 +1,72 @@ /* eslint-disable no-console */ +// Runs a demo. The demos are in a folder for each topic, such as demo/tables/basic-table.ts +// +// npm run demo pick a demo from the list, typing to search it +// npm run demo tables/basic-table run that demo +// npm run demo basic-table run the demo with that name +// npm run demo tables pick from the demos in that topic +// npm run demo table border run the only demo matching every word, or pick from the ones that do import fs from "fs"; import path from "path"; import inquirer from "inquirer"; import { $ } from "execa"; -export type Answers = { - readonly type: "list" | "number"; - readonly demoNumber?: number; - readonly demoFile?: number; -}; - const dir = "./demo"; -const fileNames = fs.readdirSync(dir); -const keys = fileNames.map((f) => path.parse(f).name); -const getFileNumber = (file: string): number => { - const [firstPart] = file.split("-"); +// Every demo, as its topic and name, such as "tables/basic-table" +const demos = fs + .readdirSync(dir, { withFileTypes: true }) + .filter((entry) => entry.isDirectory() && entry.name !== "assets") + .flatMap((topic) => + fs + .readdirSync(path.join(dir, topic.name)) + .filter((file) => file.endsWith(".ts")) + .map((file) => `${topic.name}/${path.parse(file).name}`), + ) + .sort(); - return Number(firstPart); +// The demos whose topic or name has every word of the search in it +const search = (term: string): readonly string[] => { + const words = term.toLowerCase().split(/\s+/).filter(Boolean); + + return demos.filter((demo) => words.every((word) => demo.includes(word))); }; -const demoFiles = keys.filter((file) => !isNaN(getFileNumber(file))).sort((a, b) => getFileNumber(a) - getFileNumber(b)); +// A path to a demo works too, such as demo/tables/basic-table.ts +const term = process.argv + .slice(2) + .join(" ") + .replace(/^(\.\/)?demo\//, "") + .replace(/\.ts$/, ""); +const topics = new Set(demos.map((demo) => path.dirname(demo))); +// A demo's name runs it, but a topic's name lists its demos, even when one of them has the topic's name. +// Searching for "text/" rather than "text" leaves out the demos of other topics, such as text-boxes +const query = topics.has(term) ? `${term}/` : term; +const found = demos.includes(term) ? [term] : topics.has(term) ? [] : demos.filter((demo) => demo.endsWith(`/${term}`)); +const matches = found.length === 1 ? found : search(query); -const firstArg = process.argv[2]; -const firstArgNumber = Number.parseInt(firstArg, 10); -let demoNumber: number; -if (firstArg && !isNaN(firstArgNumber)) { - demoNumber = firstArgNumber; +let demo: string; +if (matches.length === 0) { + console.error(`No demo matches "${term}". Run npm run demo to pick one from the list`); + process.exit(1); +} else if (term && matches.length === 1) { + demo = matches[0]; } else { - const answers = await inquirer.prompt([ + const answers = await inquirer.prompt<{ readonly demo: string }>([ { - type: "select", - name: "type", - message: "Select demo from a list or via number", - choices: ["list", "number"], - }, - { - type: "select", - name: "demoFile", - message: "What demo do you wish to run?", - choices: demoFiles, - filter: (input: string) => parseInt(input.split("-")[0], 10), - when: (a) => a.type === "list", - }, - { - type: "number", - name: "demoNumber", - message: "What demo do you wish to run? (Enter a number)", - default: 1, - when: (a) => a.type === "number", + type: "search", + name: "demo", + message: "Which demo do you want to run? Type to search", + source: (input: string | undefined) => search(input ?? ""), + initialValue: query, + pageSize: 20, }, ]); - demoNumber = answers.demoNumber ?? answers.demoFile ?? 1; + demo = answers.demo; } -const files = fs.readdirSync(dir).filter((fn) => fn.startsWith(demoNumber.toString())); - -if (files.length === 0) { - console.error(`demo number ${demoNumber} does not exist`); -} else { - const filePath = path.join(dir, files[0]); - - console.log(`Running demo ${demoNumber}: ${files[0]}`); - const { stdout } = await $`tsx ${filePath}`; - console.log(stdout); - console.log("Successfully created document!"); -} +const filePath = path.join(dir, `${demo}.ts`); +console.log(`Running demo ${demo}`); +const { stdout } = await $`tsx ${filePath}`; +console.log(stdout); +console.log("Successfully created document!"); diff --git a/demo/21-bookmarks.ts b/demo/links-and-bookmarks/bookmarks.ts similarity index 100% rename from demo/21-bookmarks.ts rename to demo/links-and-bookmarks/bookmarks.ts diff --git a/demo/35-hyperlinks.ts b/demo/links-and-bookmarks/hyperlinks.ts similarity index 99% rename from demo/35-hyperlinks.ts rename to demo/links-and-bookmarks/hyperlinks.ts index a1c579bd21..4a6719980c 100644 --- a/demo/35-hyperlinks.ts +++ b/demo/links-and-bookmarks/hyperlinks.ts @@ -99,7 +99,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100, diff --git a/demo/64-complex-numbering-text.ts b/demo/lists/multi-level-number-text.ts similarity index 100% rename from demo/64-complex-numbering-text.ts rename to demo/lists/multi-level-number-text.ts diff --git a/demo/29-numbered-lists.ts b/demo/lists/numbered-lists.ts similarity index 100% rename from demo/29-numbered-lists.ts rename to demo/lists/numbered-lists.ts diff --git a/demo/3-numbering-and-bullet-points.ts b/demo/lists/numbering-and-bullet-points.ts similarity index 100% rename from demo/3-numbering-and-bullet-points.ts rename to demo/lists/numbering-and-bullet-points.ts diff --git a/demo/68-numbering-instances-and-starting-number.ts b/demo/lists/numbering-instances-and-starting-number.ts similarity index 100% rename from demo/68-numbering-instances-and-starting-number.ts rename to demo/lists/numbering-instances-and-starting-number.ts diff --git a/demo/102-numbering-level-paragraph-style.ts b/demo/lists/numbering-level-paragraph-style.ts similarity index 100% rename from demo/102-numbering-level-paragraph-style.ts rename to demo/lists/numbering-level-paragraph-style.ts diff --git a/demo/57-add-parent-numbered-lists.ts b/demo/lists/parent-number-in-sub-levels.ts similarity index 100% rename from demo/57-add-parent-numbered-lists.ts rename to demo/lists/parent-number-in-sub-levels.ts diff --git a/demo/55-math.ts b/demo/math/math.ts similarity index 100% rename from demo/55-math.ts rename to demo/math/math.ts diff --git a/demo/67-column-break.ts b/demo/page-layout/column-break.ts similarity index 100% rename from demo/67-column-break.ts rename to demo/page-layout/column-break.ts diff --git a/demo/69-different-width-columns.ts b/demo/page-layout/different-width-columns.ts similarity index 100% rename from demo/69-different-width-columns.ts rename to demo/page-layout/different-width-columns.ts diff --git a/demo/7-landscape.ts b/demo/page-layout/landscape.ts similarity index 100% rename from demo/7-landscape.ts rename to demo/page-layout/landscape.ts diff --git a/demo/70-line-numbers-suppression.ts b/demo/page-layout/line-numbers-suppression.ts similarity index 100% rename from demo/70-line-numbers-suppression.ts rename to demo/page-layout/line-numbers-suppression.ts diff --git a/demo/40-line-numbers.ts b/demo/page-layout/line-numbers.ts similarity index 100% rename from demo/40-line-numbers.ts rename to demo/page-layout/line-numbers.ts diff --git a/demo/44-multiple-columns.ts b/demo/page-layout/multiple-columns.ts similarity index 100% rename from demo/44-multiple-columns.ts rename to demo/page-layout/multiple-columns.ts diff --git a/demo/16-multiple-sections.ts b/demo/page-layout/multiple-sections.ts similarity index 100% rename from demo/16-multiple-sections.ts rename to demo/page-layout/multiple-sections.ts diff --git a/demo/71-page-borders-2.ts b/demo/page-layout/page-border-styles.ts similarity index 100% rename from demo/71-page-borders-2.ts rename to demo/page-layout/page-border-styles.ts diff --git a/demo/6-page-borders.ts b/demo/page-layout/page-borders.ts similarity index 100% rename from demo/6-page-borders.ts rename to demo/page-layout/page-borders.ts diff --git a/demo/65-page-sizes.ts b/demo/page-layout/page-sizes.ts similarity index 100% rename from demo/65-page-sizes.ts rename to demo/page-layout/page-sizes.ts diff --git a/demo/58-section-types.ts b/demo/page-layout/section-types.ts similarity index 100% rename from demo/58-section-types.ts rename to demo/page-layout/section-types.ts diff --git a/demo/48-vertical-align.ts b/demo/page-layout/vertical-align.ts similarity index 100% rename from demo/48-vertical-align.ts rename to demo/page-layout/vertical-align.ts diff --git a/demo/39-page-numbers.ts b/demo/page-numbers/page-number-format.ts similarity index 100% rename from demo/39-page-numbers.ts rename to demo/page-numbers/page-number-format.ts diff --git a/demo/14-page-numbers.ts b/demo/page-numbers/page-numbers.ts similarity index 100% rename from demo/14-page-numbers.ts rename to demo/page-numbers/page-numbers.ts diff --git a/demo/42-restart-page-numbers.ts b/demo/page-numbers/restart-page-numbers.ts similarity index 100% rename from demo/42-restart-page-numbers.ts rename to demo/page-numbers/restart-page-numbers.ts diff --git a/demo/47-number-of-total-pages-section.ts b/demo/page-numbers/total-pages-in-section.ts similarity index 100% rename from demo/47-number-of-total-pages-section.ts rename to demo/page-numbers/total-pages-in-section.ts diff --git a/demo/15-page-break-before.ts b/demo/paragraphs/page-break-before.ts similarity index 100% rename from demo/15-page-break-before.ts rename to demo/paragraphs/page-break-before.ts diff --git a/demo/26-paragraph-borders.ts b/demo/paragraphs/paragraph-borders.ts similarity index 100% rename from demo/26-paragraph-borders.ts rename to demo/paragraphs/paragraph-borders.ts diff --git a/demo/62-paragraph-spacing.ts b/demo/paragraphs/paragraph-spacing.ts similarity index 100% rename from demo/62-paragraph-spacing.ts rename to demo/paragraphs/paragraph-spacing.ts diff --git a/demo/84-positional-tabs.ts b/demo/paragraphs/positional-tabs.ts similarity index 100% rename from demo/84-positional-tabs.ts rename to demo/paragraphs/positional-tabs.ts diff --git a/demo/75-tab-stops.ts b/demo/paragraphs/tab-stops.ts similarity index 100% rename from demo/75-tab-stops.ts rename to demo/paragraphs/tab-stops.ts diff --git a/demo/120-custom-shapes.ts b/demo/shapes/custom-shapes.ts similarity index 100% rename from demo/120-custom-shapes.ts rename to demo/shapes/custom-shapes.ts diff --git a/demo/107-inline-shapes.ts b/demo/shapes/inline-shapes.ts similarity index 100% rename from demo/107-inline-shapes.ts rename to demo/shapes/inline-shapes.ts diff --git a/demo/110-shape-connectors.ts b/demo/shapes/shape-connectors.ts similarity index 100% rename from demo/110-shape-connectors.ts rename to demo/shapes/shape-connectors.ts diff --git a/demo/112-shape-diagrams.ts b/demo/shapes/shape-diagrams.ts similarity index 98% rename from demo/112-shape-diagrams.ts rename to demo/shapes/shape-diagrams.ts index 328700ada9..e6958fde46 100644 --- a/demo/112-shape-diagrams.ts +++ b/demo/shapes/shape-diagrams.ts @@ -11,7 +11,7 @@ const label = (text: string, color = "FFFFFF"): Paragraph => const arrow = { color: "404040", width: 1.25, endArrow: "triangle" } as const; -const logo = { type: "png", data: fs.readFileSync("./demo/images/linux-png.png") } as const; +const logo = { type: "png", data: fs.readFileSync("./demo/assets/images/linux-png.png") } as const; // A card: a picture and a caption, grouped so they move together. Its children are positioned relative to each other const card = (id: string, caption: string, left: number): IShapeCanvasChildOptions => ({ diff --git a/demo/115-shape-document-styles.ts b/demo/shapes/shape-document-styles.ts similarity index 100% rename from demo/115-shape-document-styles.ts rename to demo/shapes/shape-document-styles.ts diff --git a/demo/109-shape-groups.ts b/demo/shapes/shape-groups.ts similarity index 100% rename from demo/109-shape-groups.ts rename to demo/shapes/shape-groups.ts diff --git a/demo/113-shape-layout.ts b/demo/shapes/shape-layout.ts similarity index 100% rename from demo/113-shape-layout.ts rename to demo/shapes/shape-layout.ts diff --git a/demo/117-shape-page-layout.ts b/demo/shapes/shape-page-layout.ts similarity index 100% rename from demo/117-shape-page-layout.ts rename to demo/shapes/shape-page-layout.ts diff --git a/demo/111-shape-styles.ts b/demo/shapes/shape-styles.ts similarity index 99% rename from demo/111-shape-styles.ts rename to demo/shapes/shape-styles.ts index e8f9209311..ff29ba3343 100644 --- a/demo/111-shape-styles.ts +++ b/demo/shapes/shape-styles.ts @@ -12,7 +12,7 @@ const space = (): TextRun => new TextRun(" "); const centred = (text: string, color = "000000"): Paragraph => new Paragraph({ alignment: AlignmentType.CENTER, children: [new TextRun({ text, color, bold: true })] }); -const photo = { type: "jpg", data: fs.readFileSync("./demo/images/cat.jpg") } as const; +const photo = { type: "jpg", data: fs.readFileSync("./demo/assets/images/cat.jpg") } as const; const doc = new Document({ sections: [ diff --git a/demo/116-shape-swimlanes.ts b/demo/shapes/shape-swimlanes.ts similarity index 100% rename from demo/116-shape-swimlanes.ts rename to demo/shapes/shape-swimlanes.ts diff --git a/demo/108-shapes.ts b/demo/shapes/shapes.ts similarity index 100% rename from demo/108-shapes.ts rename to demo/shapes/shapes.ts diff --git a/demo/51-character-styles.ts b/demo/styles/character-styles.ts similarity index 100% rename from demo/51-character-styles.ts rename to demo/styles/character-styles.ts diff --git a/demo/11-declarative-styles-2.ts b/demo/styles/default-and-paragraph-styles.ts similarity index 97% rename from demo/11-declarative-styles-2.ts rename to demo/styles/default-and-paragraph-styles.ts index 98b362e223..6f48b20420 100644 --- a/demo/11-declarative-styles-2.ts +++ b/demo/styles/default-and-paragraph-styles.ts @@ -223,7 +223,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 100, height: 100, @@ -273,7 +273,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 100, height: 100, @@ -289,7 +289,7 @@ const doc = new Document({ children: [ new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 100, height: 100, diff --git a/demo/2-declarative-styles.ts b/demo/styles/default-styles.ts similarity index 100% rename from demo/2-declarative-styles.ts rename to demo/styles/default-styles.ts diff --git a/demo/95-paragraph-style-with-shading-and-borders.ts b/demo/styles/paragraph-style-with-shading-and-borders.ts similarity index 100% rename from demo/95-paragraph-style-with-shading-and-borders.ts rename to demo/styles/paragraph-style-with-shading-and-borders.ts diff --git a/demo/27-declarative-styles-3.ts b/demo/styles/paragraph-styles.ts similarity index 100% rename from demo/27-declarative-styles-3.ts rename to demo/styles/paragraph-styles.ts diff --git a/demo/119-theme-colors.ts b/demo/styles/theme-colors.ts similarity index 100% rename from demo/119-theme-colors.ts rename to demo/styles/theme-colors.ts diff --git a/demo/118-theme.ts b/demo/styles/theme.ts similarity index 100% rename from demo/118-theme.ts rename to demo/styles/theme.ts diff --git a/demo/13-xml-styles.ts b/demo/styles/xml-styles.ts similarity index 100% rename from demo/13-xml-styles.ts rename to demo/styles/xml-styles.ts diff --git a/demo/4-basic-table.ts b/demo/tables/basic-table.ts similarity index 100% rename from demo/4-basic-table.ts rename to demo/tables/basic-table.ts diff --git a/demo/31-tables.ts b/demo/tables/cell-alignment-and-text-direction.ts similarity index 100% rename from demo/31-tables.ts rename to demo/tables/cell-alignment-and-text-direction.ts diff --git a/demo/34-floating-tables.ts b/demo/tables/floating-tables.ts similarity index 100% rename from demo/34-floating-tables.ts rename to demo/tables/floating-tables.ts diff --git a/demo/32-merge-and-shade-table-cells.ts b/demo/tables/merge-and-shade-cells.ts similarity index 100% rename from demo/32-merge-and-shade-table-cells.ts rename to demo/tables/merge-and-shade-cells.ts diff --git a/demo/41-merge-table-cells-2.ts b/demo/tables/merge-many-cells.ts similarity index 100% rename from demo/41-merge-table-cells-2.ts rename to demo/tables/merge-many-cells.ts diff --git a/demo/104-percentage-width-table.ts b/demo/tables/percentage-width-table.ts similarity index 100% rename from demo/104-percentage-width-table.ts rename to demo/tables/percentage-width-table.ts diff --git a/demo/77-side-by-side-tables.ts b/demo/tables/side-by-side-tables.ts similarity index 100% rename from demo/77-side-by-side-tables.ts rename to demo/tables/side-by-side-tables.ts diff --git a/demo/49-table-borders.ts b/demo/tables/table-borders.ts similarity index 100% rename from demo/49-table-borders.ts rename to demo/tables/table-borders.ts diff --git a/demo/20-table-cell-borders.ts b/demo/tables/table-cell-borders.ts similarity index 100% rename from demo/20-table-cell-borders.ts rename to demo/tables/table-cell-borders.ts diff --git a/demo/79-table-from-data-source.ts b/demo/tables/table-from-data-source.ts similarity index 100% rename from demo/79-table-from-data-source.ts rename to demo/tables/table-from-data-source.ts diff --git a/demo/100-table-look.ts b/demo/tables/table-look.ts similarity index 97% rename from demo/100-table-look.ts rename to demo/tables/table-look.ts index 93e1da0736..23f9886221 100644 --- a/demo/100-table-look.ts +++ b/demo/tables/table-look.ts @@ -107,6 +107,5 @@ const doc = new Document({ }); Packer.toBuffer(doc).then((buffer) => { - fs.writeFileSync("97-table-look.docx", buffer); - console.log("Document created successfully at 97-table-look.docx"); + fs.writeFileSync("My Document.docx", buffer); }); diff --git a/demo/25-table-xml-styles.ts b/demo/tables/table-xml-styles.ts similarity index 100% rename from demo/25-table-xml-styles.ts rename to demo/tables/table-xml-styles.ts diff --git a/demo/96-template-document.ts b/demo/templates/custom-placeholder-delimiters.ts similarity index 97% rename from demo/96-template-document.ts rename to demo/templates/custom-placeholder-delimiters.ts index 64454dd664..1d01851b45 100644 --- a/demo/96-template-document.ts +++ b/demo/templates/custom-placeholder-delimiters.ts @@ -60,7 +60,7 @@ patchDocument({ }), new ImageRun({ type: "png", - data: fs.readFileSync("./demo/images/dog.png"), + data: fs.readFileSync("./demo/assets/images/dog.png"), transformation: { width: 100, height: 100 }, }), ], @@ -91,7 +91,7 @@ patchDocument({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100 }, }), ], diff --git a/demo/93-template-document.ts b/demo/templates/field-trip-form.ts similarity index 100% rename from demo/93-template-document.ts rename to demo/templates/field-trip-form.ts diff --git a/demo/86-generate-template.ts b/demo/templates/generate-template.ts similarity index 100% rename from demo/86-generate-template.ts rename to demo/templates/generate-template.ts diff --git a/demo/89-template-document.ts b/demo/templates/keep-original-styles.ts similarity index 100% rename from demo/89-template-document.ts rename to demo/templates/keep-original-styles.ts diff --git a/demo/85-template-document.ts b/demo/templates/patch-document.ts similarity index 97% rename from demo/85-template-document.ts rename to demo/templates/patch-document.ts index 24ab1ceabf..bd89200fe7 100644 --- a/demo/85-template-document.ts +++ b/demo/templates/patch-document.ts @@ -60,7 +60,7 @@ patchDocument({ }), new ImageRun({ type: "png", - data: fs.readFileSync("./demo/images/dog.png"), + data: fs.readFileSync("./demo/assets/images/dog.png"), transformation: { width: 100, height: 100 }, }), ], @@ -91,7 +91,7 @@ patchDocument({ children: [ new ImageRun({ type: "jpg", - data: fs.readFileSync("./demo/images/image1.jpeg"), + data: fs.readFileSync("./demo/assets/images/image1.jpeg"), transformation: { width: 100, height: 100 }, }), ], diff --git a/demo/88-template-document.ts b/demo/templates/patches-from-data.ts similarity index 100% rename from demo/88-template-document.ts rename to demo/templates/patches-from-data.ts diff --git a/demo/87-template-document.ts b/demo/templates/repeated-placeholder.ts similarity index 100% rename from demo/87-template-document.ts rename to demo/templates/repeated-placeholder.ts diff --git a/demo/94-texbox.ts b/demo/text-boxes/text-box.ts similarity index 100% rename from demo/94-texbox.ts rename to demo/text-boxes/text-box.ts diff --git a/demo/61-text-frame.ts b/demo/text-boxes/text-frame.ts similarity index 100% rename from demo/61-text-frame.ts rename to demo/text-boxes/text-frame.ts diff --git a/demo/99-wps-text-box.ts b/demo/text-boxes/wps-text-box.ts similarity index 98% rename from demo/99-wps-text-box.ts rename to demo/text-boxes/wps-text-box.ts index 6a8af32f1e..3183ce1ad1 100644 --- a/demo/99-wps-text-box.ts +++ b/demo/text-boxes/wps-text-box.ts @@ -1,6 +1,6 @@ -// WPS (WordProcessing Shape) text boxes - modern DrawingML-based alternative to legacy VML text boxes (demo 94) +// WPS (WordProcessing Shape) text boxes - modern DrawingML-based alternative to legacy VML text boxes (text-boxes/text-box.ts) // Demonstrates: basic text box, styled fill/outline, rotation, floating positioning, and vertical alignment -// WpsShapeRun is deprecated. For new documents, use ShapeRun from "docx/shapes" (demo 108), which draws any of the +// WpsShapeRun is deprecated. For new documents, use ShapeRun from "docx/shapes" (shapes/shapes.ts), which draws any of the // preset shapes, with text, fills, lines and effects. import * as fs from "fs"; diff --git a/demo/90-check-boxes.ts b/demo/text/check-boxes.ts similarity index 100% rename from demo/90-check-boxes.ts rename to demo/text/check-boxes.ts diff --git a/demo/53-chinese.ts b/demo/text/chinese.ts similarity index 100% rename from demo/53-chinese.ts rename to demo/text/chinese.ts diff --git a/demo/92-declarative-custom-fonts.ts b/demo/text/custom-fonts-in-styles.ts similarity index 100% rename from demo/92-declarative-custom-fonts.ts rename to demo/text/custom-fonts-in-styles.ts diff --git a/demo/91-custom-fonts.ts b/demo/text/custom-fonts.ts similarity index 100% rename from demo/91-custom-fonts.ts rename to demo/text/custom-fonts.ts diff --git a/demo/45-highlighting-text.ts b/demo/text/highlighting-text.ts similarity index 100% rename from demo/45-highlighting-text.ts rename to demo/text/highlighting-text.ts diff --git a/demo/52-japanese.ts b/demo/text/japanese.ts similarity index 100% rename from demo/52-japanese.ts rename to demo/text/japanese.ts diff --git a/demo/83-setting-languages.ts b/demo/text/languages.ts similarity index 100% rename from demo/83-setting-languages.ts rename to demo/text/languages.ts diff --git a/demo/22-right-to-left-text.ts b/demo/text/right-to-left-text.ts similarity index 100% rename from demo/22-right-to-left-text.ts rename to demo/text/right-to-left-text.ts diff --git a/demo/46-shading-text.ts b/demo/text/shading-text.ts similarity index 100% rename from demo/46-shading-text.ts rename to demo/text/shading-text.ts diff --git a/demo/80-thai-distributed.ts b/demo/text/thai-distributed-with-indent.ts similarity index 100% rename from demo/80-thai-distributed.ts rename to demo/text/thai-distributed-with-indent.ts diff --git a/demo/78-thai-distributed.ts b/demo/text/thai-distributed.ts similarity index 100% rename from demo/78-thai-distributed.ts rename to demo/text/thai-distributed.ts diff --git a/demo/72-word-wrap.ts b/demo/text/word-wrap.ts similarity index 100% rename from demo/72-word-wrap.ts rename to demo/text/word-wrap.ts diff --git a/demo/98-track-revisions-2.ts b/demo/track-changes/track-formatting-and-table-revisions.ts similarity index 99% rename from demo/98-track-revisions-2.ts rename to demo/track-changes/track-formatting-and-table-revisions.ts index 207a12fb12..9ab7df5c16 100644 --- a/demo/98-track-revisions-2.ts +++ b/demo/track-changes/track-formatting-and-table-revisions.ts @@ -493,6 +493,5 @@ const doc = new Document({ }); Packer.toBuffer(doc).then((buffer) => { - fs.writeFileSync("98-track-revisions-2.docx", buffer); - console.log("Document created successfully at 98-track-revisions-2.docx"); + fs.writeFileSync("My Document.docx", buffer); }); diff --git a/demo/103-track-change-images.ts b/demo/track-changes/track-image-revisions.ts similarity index 93% rename from demo/103-track-change-images.ts rename to demo/track-changes/track-image-revisions.ts index 9fba528bd2..371cf64093 100644 --- a/demo/103-track-change-images.ts +++ b/demo/track-changes/track-image-revisions.ts @@ -7,7 +7,7 @@ import { AlignmentType, Document, ImageRun, Packer, Paragraph, TextRun } from "d const REVISION_DATE = "2020-10-06T09:00:00Z"; const REVISION_AUTHOR = "Firstname Lastname"; -const imagePath = "./demo/images/dog.png"; +const imagePath = "./demo/assets/images/dog.png"; const doc = new Document({ features: { @@ -75,6 +75,5 @@ const doc = new Document({ }); Packer.toBuffer(doc).then((buffer) => { - fs.writeFileSync("101-track-change-images.docx", buffer); - console.log("Document created successfully at 101-track-change-images.docx"); + fs.writeFileSync("My Document.docx", buffer); }); diff --git a/demo/60-track-revisions.ts b/demo/track-changes/track-revisions.ts similarity index 100% rename from demo/60-track-revisions.ts rename to demo/track-changes/track-revisions.ts diff --git a/demo/106-image-watermark.ts b/demo/watermarks/image-watermark.ts similarity index 98% rename from demo/106-image-watermark.ts rename to demo/watermarks/image-watermark.ts index e701822ca3..c5fdc9e101 100644 --- a/demo/106-image-watermark.ts +++ b/demo/watermarks/image-watermark.ts @@ -14,7 +14,7 @@ const doc = new Document({ children: [ new ImageWatermark({ type: "png", - data: fs.readFileSync("./demo/images/dog.png"), + data: fs.readFileSync("./demo/assets/images/dog.png"), transformation: { width: 400, height: 400, diff --git a/demo/105-text-watermark.ts b/demo/watermarks/text-watermark.ts similarity index 100% rename from demo/105-text-watermark.ts rename to demo/watermarks/text-watermark.ts diff --git a/docs/usage/bookmarks.md b/docs/usage/bookmarks.md index 4d9aff4da2..609f48c038 100644 --- a/docs/usage/bookmarks.md +++ b/docs/usage/bookmarks.md @@ -183,6 +183,6 @@ new InternalHyperlink({ ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/21-bookmarks.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/links-and-bookmarks/bookmarks.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/21-bookmarks.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/links-and-bookmarks/bookmarks.ts_ diff --git a/docs/usage/bullet-points.md b/docs/usage/bullet-points.md index 66026162c7..044e838ee8 100644 --- a/docs/usage/bullet-points.md +++ b/docs/usage/bullet-points.md @@ -213,6 +213,6 @@ new Paragraph({ ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/3-numbering-and-bullet-points.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/lists/numbering-and-bullet-points.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/3-numbering-and-bullet-points.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/lists/numbering-and-bullet-points.ts_ diff --git a/docs/usage/change-tracking.md b/docs/usage/change-tracking.md index becac4b738..a7c1b9e672 100644 --- a/docs/usage/change-tracking.md +++ b/docs/usage/change-tracking.md @@ -463,12 +463,12 @@ The `insertion` and `deletion` options accept the same properties as text track ### Track Revisions (Text) -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/60-track-revisions.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/track-changes/track-revisions.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/60-track-revisions.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/track-changes/track-revisions.ts_ ### Track Change Images -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/103-track-change-images.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/track-changes/track-image-revisions.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/103-track-change-images.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/track-changes/track-image-revisions.ts_ diff --git a/docs/usage/chart-templates.md b/docs/usage/chart-templates.md index a5f90e111c..26d40fc0c4 100644 --- a/docs/usage/chart-templates.md +++ b/docs/usage/chart-templates.md @@ -115,6 +115,6 @@ The template's charts without a placeholder are left as they are, whatever they ## Example -_Source: https://github.com/dolanmiu/docx/blob/master/demo/124-chart-data-in-templates.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/charts/chart-data-in-templates.ts_ -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/124-chart-data-in-templates.ts ":include :type=code typescript") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/charts/chart-data-in-templates.ts ":include :type=code typescript") diff --git a/docs/usage/charts.md b/docs/usage/charts.md index b4a8fdc97f..97bac508d5 100644 --- a/docs/usage/charts.md +++ b/docs/usage/charts.md @@ -134,38 +134,38 @@ In a page without a bundler, load the charts after `docx`: `dist/charts.umd.cjs` A chart of each of the first types, with a small chart in the header, two charts in a table and one floating beside its text. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/121-charts.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/charts/charts.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/121-charts.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/charts/charts.ts_ ### Chart Options A combo chart with a secondary axis, dates, axes in reverse and on a logarithmic scale, labels and colours, fonts and fills, and radar and bubble charts. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/122-chart-options.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/charts/chart-options.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/122-chart-options.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/charts/chart-options.ts_ ### More Charts Stock charts, pie of pie and bar of pie charts, categories in groups, trendlines and error bars, the labels of single points, a pulled-out slice, a hidden legend entry, a data table, and a line joined across an empty value. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/125-more-charts.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/charts/more-charts.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/125-more-charts.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/charts/more-charts.ts_ ### Charts in Templates A column, a pie and a line chart put in a template saved by Word, where its placeholders were. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/123-charts-in-templates.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/charts/charts-in-templates.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/123-charts-in-templates.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/charts/charts-in-templates.ts_ ### Chart Data in Templates A template's charts, a column, a doughnut and a line chart, given new data, with more series and points than they had, keeping their look. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/124-chart-data-in-templates.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/charts/chart-data-in-templates.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/124-chart-data-in-templates.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/charts/chart-data-in-templates.ts_ diff --git a/docs/usage/checkboxes.md b/docs/usage/checkboxes.md index c32b383c03..8eac2b2416 100644 --- a/docs/usage/checkboxes.md +++ b/docs/usage/checkboxes.md @@ -163,6 +163,6 @@ const doc = new Document({ ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/90-check-boxes.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/text/check-boxes.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/90-check-boxes.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/text/check-boxes.ts_ diff --git a/docs/usage/columns.md b/docs/usage/columns.md index 8b558e76e4..471ee5e1c7 100644 --- a/docs/usage/columns.md +++ b/docs/usage/columns.md @@ -206,18 +206,18 @@ const doc = new Document({ ### Multiple Columns -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/44-multiple-columns.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/multiple-columns.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/44-multiple-columns.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/multiple-columns.ts_ ### Column Break -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/67-column-break.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/column-break.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/67-column-break.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/column-break.ts_ ### Different Width Columns -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/69-different-width-columns.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/different-width-columns.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/69-different-width-columns.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/different-width-columns.ts_ diff --git a/docs/usage/comments.md b/docs/usage/comments.md index 66a2c95841..02834d608b 100644 --- a/docs/usage/comments.md +++ b/docs/usage/comments.md @@ -279,12 +279,12 @@ Packer.toBuffer(doc).then((buffer) => { ### Basic usage -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/73-comments.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/comments/comments.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/73-comments.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/comments/comments.ts_ ### Comment Replies and Resolved state -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/101-comment-replies.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/comments/comment-replies.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/101-comment-replies.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/comments/comment-replies.ts_ diff --git a/docs/usage/endnotes.md b/docs/usage/endnotes.md index f058a4261a..6d97f7e0d3 100644 --- a/docs/usage/endnotes.md +++ b/docs/usage/endnotes.md @@ -83,4 +83,4 @@ Insert `EndnoteReferenceRun` in paragraphs to create reference markers: ## Demo -_Source: https://github.com/dolanmiu/docx/blob/master/demo/97-endnotes.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/footnotes-and-endnotes/endnotes.ts_ diff --git a/docs/usage/fields.md b/docs/usage/fields.md index 0168f9bf35..79be31a0aa 100644 --- a/docs/usage/fields.md +++ b/docs/usage/fields.md @@ -74,6 +74,6 @@ const paragraph = new Paragraph({ ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/66-fields.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/fields/fields.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/66-fields.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/fields/fields.ts_ diff --git a/docs/usage/fonts.md b/docs/usage/fonts.md index 14057000bc..5be28a8a34 100644 --- a/docs/usage/fonts.md +++ b/docs/usage/fonts.md @@ -253,12 +253,12 @@ Packer.toBlob(doc).then((blob) => { ### Embedding Custom Fonts -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/91-custom-fonts.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/text/custom-fonts.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/91-custom-fonts.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/text/custom-fonts.ts_ ### Declarative Custom Fonts -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/92-declarative-custom-fonts.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/text/custom-fonts-in-styles.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/92-declarative-custom-fonts.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/text/custom-fonts-in-styles.ts_ diff --git a/docs/usage/footnotes.md b/docs/usage/footnotes.md index 223522bb8c..1cb7e3076d 100644 --- a/docs/usage/footnotes.md +++ b/docs/usage/footnotes.md @@ -158,6 +158,6 @@ const doc = new Document({ ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/17-footnotes.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/footnotes-and-endnotes/footnotes.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/17-footnotes.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/footnotes-and-endnotes/footnotes.ts_ diff --git a/docs/usage/headers-and-footers.md b/docs/usage/headers-and-footers.md index dacfdca898..194f8c2db3 100644 --- a/docs/usage/headers-and-footers.md +++ b/docs/usage/headers-and-footers.md @@ -448,24 +448,24 @@ Packer.toBuffer(doc).then((buffer) => { ### Basic Header and Footer -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/8-header-footer.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/headers-and-footers/header-and-footer.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/8-header-footer.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/headers-and-footers/header-and-footer.ts_ ### Odd/Even Headers and Footers -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/63-odd-even-header-footer.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/headers-and-footers/odd-and-even-headers-and-footers.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/63-odd-even-header-footer.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/headers-and-footers/odd-and-even-headers-and-footers.ts_ ### Header and Footer Margins -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/59-header-footer-margins.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/headers-and-footers/header-and-footer-margins.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/59-header-footer-margins.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/headers-and-footers/header-and-footer-margins.ts_ ### Images in Header and Footer -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/9-images-in-header-and-footer.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/images/images-in-header-and-footer.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/9-images-in-header-and-footer.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/images/images-in-header-and-footer.ts_ diff --git a/docs/usage/hyperlinks.md b/docs/usage/hyperlinks.md index a58a240aac..cc69d2956b 100644 --- a/docs/usage/hyperlinks.md +++ b/docs/usage/hyperlinks.md @@ -85,9 +85,9 @@ const paragraph = new Paragraph({ ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/35-hyperlinks.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/links-and-bookmarks/hyperlinks.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/35-hyperlinks.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/links-and-bookmarks/hyperlinks.ts_ ## Styling hyperlinks diff --git a/docs/usage/images.md b/docs/usage/images.md index e20a8481d5..4544791a1b 100644 --- a/docs/usage/images.md +++ b/docs/usage/images.md @@ -38,7 +38,7 @@ To create a `floating` image on top of text: ```ts const image = new ImageRun({ type: 'gif', - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 200, height: 200, @@ -59,7 +59,7 @@ By default with no arguments, its an `inline` image: ```ts const image = new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 100, height: 100, @@ -217,7 +217,7 @@ For example: ```ts const image = new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 200, height: 200, @@ -266,7 +266,7 @@ For example: ```ts const image = new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 200, height: 200, @@ -297,7 +297,7 @@ Use `run` to format the run the image is in, with the same options as a `TextRun ```ts const image = new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 100, height: 100 }, run: { position: "-2pt" }, }); @@ -312,7 +312,7 @@ Specifies common non-visual DrawingML properties. A name, title and description ```ts const image = new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), altText: { title: "This is an ultimate title", description: "This is an ultimate image", @@ -372,7 +372,7 @@ Crop an image by trimming a percentage off each edge before it's stretched to fi ```ts const image = new ImageRun({ type: "gif", - data: fs.readFileSync("./demo/images/pizza.gif"), + data: fs.readFileSync("./demo/assets/images/pizza.gif"), transformation: { width: 200, height: 200, @@ -420,28 +420,28 @@ See [Change Tracking – Image Revisions](usage/change-tracking.md#image-revisio Importing Images from file system path -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/5-images.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/images/images.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/5-images.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/images/images.ts_ ### Add images to header and footer Example showing how to add image to headers and footers -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/9-images-in-header-and-footer.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/images/images-in-header-and-footer.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/9-images-in-header-and-footer.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/images/images-in-header-and-footer.ts_ ### Floating images Example showing how to float images on top of text and optimally give a `margin` -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/38-text-wrapping.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/images/text-wrapping.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/38-text-wrapping.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/images/text-wrapping.ts_ ### Links and decorative images -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/114-image-links.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/images/image-links.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/114-image-links.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/images/image-links.ts_ diff --git a/docs/usage/line-numbers.md b/docs/usage/line-numbers.md index fec51f160c..ecf5a682d5 100644 --- a/docs/usage/line-numbers.md +++ b/docs/usage/line-numbers.md @@ -167,12 +167,12 @@ const doc = new Document({ ### Basic Line Numbers -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/40-line-numbers.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/line-numbers.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/40-line-numbers.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/line-numbers.ts_ ### Line Number Suppression -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/70-line-numbers-suppression.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/line-numbers-suppression.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/70-line-numbers-suppression.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/line-numbers-suppression.ts_ diff --git a/docs/usage/math.md b/docs/usage/math.md index 7470b42e08..fddb73fa2d 100644 --- a/docs/usage/math.md +++ b/docs/usage/math.md @@ -286,6 +286,6 @@ new MathLimitLower({ ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/55-math.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/math/math.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/55-math.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/math/math.ts_ diff --git a/docs/usage/numbering.md b/docs/usage/numbering.md index 3554bfdcf1..1a5ec388e5 100644 --- a/docs/usage/numbering.md +++ b/docs/usage/numbering.md @@ -290,12 +290,12 @@ The `style.style` value must match the `id` of a paragraph style defined in `sty ### Numbering and Bullet Points -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/3-numbering-and-bullet-points.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/lists/numbering-and-bullet-points.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/3-numbering-and-bullet-points.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/lists/numbering-and-bullet-points.ts_ ### Numbering with Paragraph Styles -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/102-numbering-level-paragraph-style.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/lists/numbering-level-paragraph-style.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/102-numbering-level-paragraph-style.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/lists/numbering-level-paragraph-style.ts_ diff --git a/docs/usage/packers.md b/docs/usage/packers.md index 1c0a6beb81..41bf92881d 100644 --- a/docs/usage/packers.md +++ b/docs/usage/packers.md @@ -86,10 +86,10 @@ Packer.pack(doc, "string").then((string) => { ## Demos -[Export to Base64 Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/19-export-to-base64.ts ":include") +[Export to Base64 Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/exporting/base64-string.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/19-export-to-base64.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/exporting/base64-string.ts_ -[Node.js Stream Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/74-nodejs-stream.ts ":include") +[Node.js Stream Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/exporting/node-stream.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/74-nodejs-stream.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/exporting/node-stream.ts_ diff --git a/docs/usage/page-layout.md b/docs/usage/page-layout.md index d52b47d916..8bed16626d 100644 --- a/docs/usage/page-layout.md +++ b/docs/usage/page-layout.md @@ -284,18 +284,18 @@ const doc = new Document({ ### Page Borders -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/71-page-borders-2.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/page-border-styles.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/71-page-borders-2.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/page-border-styles.ts_ ### Page Sizes -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/65-page-sizes.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/page-sizes.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/65-page-sizes.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/page-sizes.ts_ ### Landscape Orientation -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/7-landscape.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/landscape.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/7-landscape.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/landscape.ts_ diff --git a/docs/usage/page-numbers.md b/docs/usage/page-numbers.md index c0ff7efeb8..8d67c51945 100644 --- a/docs/usage/page-numbers.md +++ b/docs/usage/page-numbers.md @@ -110,14 +110,14 @@ Available separators: `COLON`, `EM_DASH`, `EN_DASH`, `HYPHEN`, `PERIOD`. Adding page numbers to Header and Footer -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/39-page-numbers.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-numbers/page-number-format.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/39-page-numbers.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-numbers/page-number-format.ts_ ### Restart Page Numbers Restarting page numbering in a new section -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/42-restart-page-numbers.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-numbers/restart-page-numbers.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/42-restart-page-numbers.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-numbers/restart-page-numbers.ts_ diff --git a/docs/usage/paragraph.md b/docs/usage/paragraph.md index 64d666a699..17bd56a570 100644 --- a/docs/usage/paragraph.md +++ b/docs/usage/paragraph.md @@ -360,7 +360,7 @@ const paragraph = new Paragraph({ ![Page Break Before in Word](https://user-images.githubusercontent.com/34742290/40176503-df3a8398-59db-11e8-8b9c-d719f13aa8b4.png) -Example: https://github.com/dolanmiu/docx/blob/master/demo/15-page-break-before.ts +Example: https://github.com/dolanmiu/docx/blob/master/demo/paragraphs/page-break-before.ts ## Page break control diff --git a/docs/usage/patcher.md b/docs/usage/patcher.md index 0a0db13f4b..c91fe2f5f8 100644 --- a/docs/usage/patcher.md +++ b/docs/usage/patcher.md @@ -82,7 +82,7 @@ patchDocument(fs.readFileSync("My Document.docx"), { }), new ImageRun({ type: "png", - data: fs.readFileSync("./demo/images/dog.png"), + data: fs.readFileSync("./demo/assets/images/dog.png"), transformation: { width: 100, height: 100 }, }), ], @@ -97,6 +97,6 @@ patchDocument(fs.readFileSync("My Document.docx"), { ## Demo -_Source: https://github.com/dolanmiu/docx/blob/master/demo/85-template-document.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/templates/patch-document.ts_ -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/85-template-document.ts ":include :type=code typescript") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/templates/patch-document.ts ":include :type=code typescript") diff --git a/docs/usage/sections.md b/docs/usage/sections.md index 1eda8c4f21..65dac23231 100644 --- a/docs/usage/sections.md +++ b/docs/usage/sections.md @@ -204,12 +204,12 @@ const doc = new Document({ ### Multiple Sections -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/16-multiple-sections.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/multiple-sections.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/16-multiple-sections.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/multiple-sections.ts_ ### Section Types -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/58-section-types.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/page-layout/section-types.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/58-section-types.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/page-layout/section-types.ts_ diff --git a/docs/usage/shapes.md b/docs/usage/shapes.md index fd02e038a3..e6b183b119 100644 --- a/docs/usage/shapes.md +++ b/docs/usage/shapes.md @@ -1079,94 +1079,94 @@ Apple Pages (checked with version 15.1) draws shapes and groups, and the group i Bars, rules and signature lines in the flow of text, as on a printed form. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/107-inline-shapes.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/inline-shapes.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/107-inline-shapes.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/inline-shapes.ts_ ### Shapes, lines and arrows Preset shapes, dashes and arrowheads, gradients, transparency, text in shapes and floating shapes. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/108-shapes.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/shapes.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/108-shapes.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/shapes.ts_ ### Shape groups A flowchart built from a group of shapes, the same group scaled down, and a floating, rotated group. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/109-shape-groups.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/shape-groups.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/109-shape-groups.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/shape-groups.ts_ ### Connectors and canvases A flowchart on a canvas whose connectors stay attached, straight, elbow and curved routes, and connectors on chosen sides. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/110-shape-connectors.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/shape-connectors.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/110-shape-connectors.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/shape-connectors.ts_ ### Shape styles Effects, pattern and picture fills, line styles, text layout and WordArt warps, custom shapes, links and decorative shapes. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/111-shape-styles.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/shape-styles.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/111-shape-styles.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/shape-styles.ts_ ### Diagrams Pictures and groups on a canvas, connector labels, connecting to a point on a shape, and connectors that go around shapes. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/112-shape-diagrams.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/shape-diagrams.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/112-shape-diagrams.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/shape-diagrams.ts_ ### Automatic layout Shapes sized to fit their text, a flowchart, an org chart and a grid laid out automatically, spread and side-by-side connectors, and labels at the start of a connector. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/113-shape-layout.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/shape-layout.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/113-shape-layout.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/shape-layout.ts_ ### Shapes in the document's styles Shapes, a canvas and a group sized to fit their text in 11pt Calibri with space after each paragraph, with a heading, a character style and an indented paragraph in a shape. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/115-shape-document-styles.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/shape-document-styles.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/115-shape-document-styles.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/shape-document-styles.ts_ ### Swimlanes A support process in swimlanes down the page, with a decision and a branch to another team, and a shorter process in lanes across the page. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/116-shape-swimlanes.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/shape-swimlanes.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/116-shape-swimlanes.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/shape-swimlanes.ts_ ### Page layout A rule as wide as the text, a sidebar sized and placed as percentages of the text's width, and an article whose text flows from one box into the next. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/117-shape-page-layout.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/shape-page-layout.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/117-shape-page-layout.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/shape-page-layout.ts_ ### Theme colours A document with a theme of its own, swatches of its colours and of lighter and darker versions of one, and a diagram in them. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/118-theme.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/styles/theme.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/118-theme.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/styles/theme.ts_ ### Custom shapes Custom shapes drawn from several paths, with shaded faces, holes, text areas, and connection points of their own on a canvas. -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/120-custom-shapes.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/shapes/custom-shapes.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/120-custom-shapes.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/shapes/custom-shapes.ts_ diff --git a/docs/usage/styling-with-js.md b/docs/usage/styling-with-js.md index 2142910f22..60e85077b4 100644 --- a/docs/usage/styling-with-js.md +++ b/docs/usage/styling-with-js.md @@ -203,6 +203,6 @@ For these properties, the rules state the following conflict resolution in case Importing Images from file system path -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/2-declarative-styles.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/styles/default-styles.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/2-declarative-styles.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/styles/default-styles.ts_ diff --git a/docs/usage/styling-with-xml.md b/docs/usage/styling-with-xml.md index 5e4647367c..8e89889d72 100644 --- a/docs/usage/styling-with-xml.md +++ b/docs/usage/styling-with-xml.md @@ -50,4 +50,4 @@ doc.add(paragraph); doc.createParagraph("Some normal text"); ``` -Example: https://github.com/dolanmiu/docx/blob/master/demo/13-xml-styles.ts +Example: https://github.com/dolanmiu/docx/blob/master/demo/styles/xml-styles.ts diff --git a/docs/usage/table-of-contents.md b/docs/usage/table-of-contents.md index 2840269229..fc929599c6 100644 --- a/docs/usage/table-of-contents.md +++ b/docs/usage/table-of-contents.md @@ -144,6 +144,6 @@ new TableOfContents("Summary", { ## Examples -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/28-table-of-contents.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/fields/table-of-contents.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/28-table-of-contents.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/fields/table-of-contents.ts_ diff --git a/docs/usage/tables.md b/docs/usage/tables.md index 48f4b66449..4b42b7fa82 100644 --- a/docs/usage/tables.md +++ b/docs/usage/tables.md @@ -394,66 +394,66 @@ const table = new Table({ #### Example -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/100-table-look.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/tables/table-look.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/100-table-look.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/tables/table-look.ts_ ## Examples -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/4-basic-table.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/tables/basic-table.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/4-basic-table.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/tables/basic-table.ts_ ### Custom borders Example showing how to add colorful borders to tables -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/20-table-cell-borders.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/tables/table-cell-borders.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/20-table-cell-borders.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/tables/table-cell-borders.ts_ ### Adding images Example showing how to add images to tables -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/24-images-to-table-cell.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/images/image-in-table-cell.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/24-images-to-table-cell.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/images/image-in-table-cell.ts_ -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/36-image-to-table-cell.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/images/image-in-header-table-cell.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/36-image-to-table-cell.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/images/image-in-header-table-cell.ts_ ### Alignment of text in a cell Example showing how align text in a table cell -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/31-tables.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/tables/cell-alignment-and-text-direction.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/31-tables.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/tables/cell-alignment-and-text-direction.ts_ ### Shading Example showing merging of columns and rows and shading -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/32-merge-and-shade-table-cells.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/tables/merge-and-shade-cells.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/32-merge-and-shade-table-cells.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/tables/merge-and-shade-cells.ts_ -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/41-merge-table-cells-2.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/tables/merge-many-cells.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/41-merge-table-cells-2.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/tables/merge-many-cells.ts_ ### Merging columns Example showing merging of columns and rows -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/43-images-to-table-cell-2.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/images/image-in-merged-table-cell.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/43-images-to-table-cell-2.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/images/image-in-merged-table-cell.ts_ ### Floating tables -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/34-floating-tables.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/tables/floating-tables.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/34-floating-tables.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/tables/floating-tables.ts_ diff --git a/docs/usage/tabs.md b/docs/usage/tabs.md index 35dcbde48a..e774cb66fc 100644 --- a/docs/usage/tabs.md +++ b/docs/usage/tabs.md @@ -185,10 +185,10 @@ new Paragraph({ ## Demos -[Tab Stops Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/75-tab-stops.ts ":include") +[Tab Stops Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/paragraphs/tab-stops.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/75-tab-stops.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/paragraphs/tab-stops.ts_ -[Positional Tabs Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/84-positional-tabs.ts ":include") +[Positional Tabs Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/paragraphs/positional-tabs.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/84-positional-tabs.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/paragraphs/positional-tabs.ts_ diff --git a/docs/usage/templates.md b/docs/usage/templates.md index c2c7e5b1cb..5d5ec340e0 100644 --- a/docs/usage/templates.md +++ b/docs/usage/templates.md @@ -278,6 +278,6 @@ patchDocument({ ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/85-template-document.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/templates/patch-document.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/85-template-document.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/templates/patch-document.ts_ diff --git a/docs/usage/text-box.md b/docs/usage/text-box.md index 2ec9d77ac0..7e90665634 100644 --- a/docs/usage/text-box.md +++ b/docs/usage/text-box.md @@ -222,6 +222,6 @@ For most use cases, **Text Frames** are recommended. See [Text Frames](usage/tex ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/94-texbox.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/text-boxes/text-box.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/94-texbox.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/text-boxes/text-box.ts_ diff --git a/docs/usage/text-frames.md b/docs/usage/text-frames.md index 483e3f60d7..cabc4914be 100644 --- a/docs/usage/text-frames.md +++ b/docs/usage/text-frames.md @@ -134,6 +134,6 @@ new Paragraph({ ## Demo -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/61-text-frame.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/text-boxes/text-frame.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/61-text-frame.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/text-boxes/text-frame.ts_ diff --git a/docs/usage/text.md b/docs/usage/text.md index a04a2ae6a6..4a8f164cd3 100644 --- a/docs/usage/text.md +++ b/docs/usage/text.md @@ -97,7 +97,7 @@ const text = new TextRun({ }); ``` -See [demo/45-highlighting-text.ts](https://github.com/dolanmiu/docx/blob/master/demo/45-highlighting-text.ts) for highlighting examples, and [demo/46-shading-text.ts](https://github.com/dolanmiu/docx/blob/master/demo/46-shading-text.ts) for shading examples. +See [demo/text/highlighting-text.ts](https://github.com/dolanmiu/docx/blob/master/demo/text/highlighting-text.ts) for highlighting examples, and [demo/text/shading-text.ts](https://github.com/dolanmiu/docx/blob/master/demo/text/shading-text.ts) for shading examples. ### Strike through diff --git a/docs/usage/themes.md b/docs/usage/themes.md index c91ce0e49e..8fe65edb7a 100644 --- a/docs/usage/themes.md +++ b/docs/usage/themes.md @@ -145,12 +145,12 @@ new ShapeRun({ ### A theme of its own -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/118-theme.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/styles/theme.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/118-theme.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/styles/theme.ts_ ### Text, tables and borders in the theme's colors -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/119-theme-colors.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/styles/theme-colors.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/119-theme-colors.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/styles/theme-colors.ts_ diff --git a/docs/usage/watermarks.md b/docs/usage/watermarks.md index 153f8d8144..4b809dc589 100644 --- a/docs/usage/watermarks.md +++ b/docs/usage/watermarks.md @@ -202,12 +202,12 @@ Word draws watermarks with VML (Vector Markup Language), the legacy drawing form ### Text Watermark -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/105-text-watermark.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/watermarks/text-watermark.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/105-text-watermark.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/watermarks/text-watermark.ts_ ### Image Watermark -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/106-image-watermark.ts ":include") +[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/watermarks/image-watermark.ts ":include") -_Source: https://github.com/dolanmiu/docx/blob/master/demo/106-image-watermark.ts_ +_Source: https://github.com/dolanmiu/docx/blob/master/demo/watermarks/image-watermark.ts_ diff --git a/scripts/render-shape-demos.sh b/scripts/render-shape-demos.sh index 89922f6fb6..8951f357cc 100755 --- a/scripts/render-shape-demos.sh +++ b/scripts/render-shape-demos.sh @@ -4,8 +4,9 @@ # # Usage: scripts/render-shape-demos.sh [output directory] [demo ...] # -# The output directory (default build/shape-demos) gets each demo's .docx, .pdf and one PNG per page. -# Without demo names, all the shape and chart demos are run. Needs the package built (npm run build) and perl. +# Each demo is its topic and name, such as shapes/shape-groups. The output directory (default build/shape-demos) gets +# each demo's .docx, .pdf and one PNG per page, named after the demo. Without demos, all the shape and chart demos are +# run. Needs the package built (npm run build) and perl. # # The pages are drawn with LibreOffice (set SOFFICE if soffice isn't on the PATH) and pdftoppm from Poppler. # When SHAPE_RENDER_IMAGE names a Docker image built from scripts/shape-demos/Dockerfile, they are drawn in @@ -21,7 +22,7 @@ OUT="${1:-build/shape-demos}" shift || true DEMOS=("$@") if [ ${#DEMOS[@]} -eq 0 ]; then - DEMOS=(107-inline-shapes 108-shapes 109-shape-groups 110-shape-connectors 111-shape-styles 112-shape-diagrams 113-shape-layout 115-shape-document-styles 116-shape-swimlanes 117-shape-page-layout 118-theme 120-custom-shapes 121-charts 122-chart-options 123-charts-in-templates 124-chart-data-in-templates 125-more-charts) + DEMOS=(shapes/inline-shapes shapes/shapes shapes/shape-groups shapes/shape-connectors shapes/shape-styles shapes/shape-diagrams shapes/shape-layout shapes/shape-document-styles shapes/shape-swimlanes shapes/shape-page-layout styles/theme shapes/custom-shapes charts/charts charts/chart-options charts/charts-in-templates charts/chart-data-in-templates charts/more-charts) fi SOFFICE="${SOFFICE:-soffice}" @@ -33,12 +34,13 @@ failed=0 for demo in "${DEMOS[@]}"; do echo "::group::$demo" npm run --silent run-ts -- "./demo/$demo.ts" - cp "My Document.docx" "$OUT/$demo.docx" + docx="$OUT/$(basename "$demo").docx" + cp "My Document.docx" "$docx" # Where the Word 2010 drawing extensions (wp14) are: a floating drawing's relative sizes come after its graphic, and # a percentage offset is the choice for a position, with its offset in EMUs as the fallback extracted="$(mktemp -d)" - unzip -q -o "$OUT/$demo.docx" -d "$extracted" + unzip -q -o "$docx" -d "$extracted" misplaced="$(perl -0ne '$all = () = /-?\d+<\/wp14:pctPos\1Offset><\/mc:Choice>-?\d+<\/wp:posOffset><\/mc:Fallback><\/mc:AlternateContent><\/wp:position\1>/g; while (/<\/a:graphic>((?:)+)<\/wp:anchor>/gs) { my $sizes = $1; $placed += () = $sizes =~ /