Compare commits
34 Commits
Author | SHA1 | Date | |
---|---|---|---|
4935878f73 | |||
440782e9cf | |||
f304220463 | |||
02a5aaf5d8 | |||
e84641c13c | |||
278b6b6a20 | |||
d369c0a74c | |||
ab9f97598c | |||
2814841226 | |||
a7d55a52f3 | |||
d436b7b339 | |||
f183d38bb3 | |||
2353b36709 | |||
00db6e7dc1 | |||
eb479c4684 | |||
68413605e9 | |||
02bd5d71d0 | |||
97a851a848 | |||
f503794e09 | |||
d0ee5fa23a | |||
0ccf0f8d7a | |||
719f7c8f9e | |||
828e30a248 | |||
6beb7208af | |||
2d342a2415 | |||
a2017fc353 | |||
709c3d9b55 | |||
950867d032 | |||
65caa531c5 | |||
64addc85ee | |||
aa02261248 | |||
6d447033c9 | |||
c888f589d0 | |||
4697d774f4 |
58
.cspell.json
Normal file
58
.cspell.json
Normal file
@ -0,0 +1,58 @@
|
||||
// cSpell Settings
|
||||
{
|
||||
// Version of the setting file. Always 0.2
|
||||
"version": "0.2",
|
||||
// language - current active spelling language
|
||||
"language": "en_US",
|
||||
"dictionaries": ["en_US", "typescript", "softwareTerms", "fonts", "npm"],
|
||||
// words - list of words to be always considered correct
|
||||
"words": [
|
||||
"Xmlable",
|
||||
"twip",
|
||||
"twips",
|
||||
"jsonify",
|
||||
"falsey",
|
||||
"aiueo",
|
||||
"iroha",
|
||||
"aiueo",
|
||||
"iroha",
|
||||
"chosung",
|
||||
"Abjad",
|
||||
"Initializable",
|
||||
"rels",
|
||||
"dolan",
|
||||
"xmlify",
|
||||
"Xmlifyed",
|
||||
"xmlified",
|
||||
"datas",
|
||||
"jszip",
|
||||
"rsid",
|
||||
"NUMPAGES",
|
||||
"ATLEAST",
|
||||
"ooxml",
|
||||
"clippy",
|
||||
"docsify"
|
||||
],
|
||||
"ignoreRegExpList": [
|
||||
"/\"w:.+\"/",
|
||||
"/\"s:.+\"/",
|
||||
"/\"a:.+\"/",
|
||||
"/\"pic:.+\"/",
|
||||
"/\"xmlns:.+\"/",
|
||||
"/\"vt:.+\"/",
|
||||
"/[^\\s]{40,}/",
|
||||
"/<xsd:.+/>/",
|
||||
"/[A-Z_]+ = \".+\"/",
|
||||
"/XmlAttributeComponent<{[^}]+}>/g",
|
||||
"/xmlKeys = {[^}]+}/g",
|
||||
"/\\.to\\.deep\\.equal\\({[^)]+}\\)/g",
|
||||
"\\.to\\.include\\.members\\(\\[[^\\]]+]\\)",
|
||||
"/new [a-zA-Z]+\\({[^£]+}\\)/g"
|
||||
],
|
||||
"ignorePaths": ["package.json", "docs/api"],
|
||||
"allowCompoundWords": true,
|
||||
// flagWords - list of words to be always considered incorrect
|
||||
// This is useful for offensive words and common spelling errors.
|
||||
// For example "hte" should be "the"
|
||||
"flagWords": ["hte"]
|
||||
}
|
10
.github/workflows/default.yml
vendored
10
.github/workflows/default.yml
vendored
@ -58,3 +58,13 @@ jobs:
|
||||
run: npm ci --force
|
||||
- name: Prettier
|
||||
run: npm run style
|
||||
cspell:
|
||||
name: CSpell
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
- name: Install Dependencies
|
||||
run: npm ci --force
|
||||
- name: Prettier
|
||||
run: npm run cspell
|
||||
|
8
.nycrc
8
.nycrc
@ -1,9 +1,9 @@
|
||||
{
|
||||
"check-coverage": true,
|
||||
"statements": 99.43,
|
||||
"branches": 96.6,
|
||||
"functions": 99.47,
|
||||
"lines": 99.43,
|
||||
"statements": 99.62,
|
||||
"branches": 96.81,
|
||||
"functions": 99.82,
|
||||
"lines": 99.62,
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
|
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"streetsidesoftware.code-spell-checker"
|
||||
]
|
||||
}
|
31
README.md
31
README.md
@ -26,21 +26,21 @@
|
||||
|
||||
Here are examples of `docx` being used with basic `HTML/JS` in a browser environment:
|
||||
|
||||
* https://codepen.io/dolanmiu/pen/RwNeObg
|
||||
* https://jsfiddle.net/dolanmiu/onadx1gu/
|
||||
- https://codepen.io/dolanmiu/pen/RwNeObg
|
||||
- https://jsfiddle.net/dolanmiu/onadx1gu/
|
||||
|
||||
Here is an example of `docx` working in `Angular`:
|
||||
|
||||
* https://stackblitz.com/edit/angular-docx
|
||||
- https://stackblitz.com/edit/angular-docx
|
||||
|
||||
Here is an example of `docx` working in `React`:
|
||||
|
||||
* https://stackblitz.com/edit/react-docx
|
||||
* https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
||||
- https://stackblitz.com/edit/react-docx
|
||||
- https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
||||
|
||||
Here is an example of `docx` working in `Vue.js`:
|
||||
|
||||
* https://stackblitz.com/edit/vuejs-docx
|
||||
- https://stackblitz.com/edit/vuejs-docx
|
||||
|
||||
## Node
|
||||
|
||||
@ -48,15 +48,15 @@ Press `endpoint` on the `RunKit` website:
|
||||
|
||||

|
||||
|
||||
* https://runkit.com/dolanmiu/docx-demo1 - Simple paragraph and text
|
||||
* https://runkit.com/dolanmiu/docx-demo2 - Advanced Paragraphs and text
|
||||
* https://runkit.com/dolanmiu/docx-demo3 - Bullet points
|
||||
* https://runkit.com/dolanmiu/docx-demo4 - Simple table
|
||||
* https://runkit.com/dolanmiu/docx-demo5 - Images
|
||||
* https://runkit.com/dolanmiu/docx-demo6 - Margins
|
||||
* https://runkit.com/dolanmiu/docx-demo7 - Landscape
|
||||
* https://runkit.com/dolanmiu/docx-demo8 - Header and Footer
|
||||
* https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
|
||||
- https://runkit.com/dolanmiu/docx-demo1 - Simple paragraph and text
|
||||
- https://runkit.com/dolanmiu/docx-demo2 - Advanced Paragraphs and text
|
||||
- https://runkit.com/dolanmiu/docx-demo3 - Bullet points
|
||||
- https://runkit.com/dolanmiu/docx-demo4 - Simple table
|
||||
- https://runkit.com/dolanmiu/docx-demo5 - Images
|
||||
- https://runkit.com/dolanmiu/docx-demo6 - Margins
|
||||
- https://runkit.com/dolanmiu/docx-demo7 - Landscape
|
||||
- https://runkit.com/dolanmiu/docx-demo8 - Header and Footer
|
||||
- https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
|
||||
|
||||
More [here](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||
|
||||
@ -88,7 +88,6 @@ Read the contribution guidelines [here](https://docx.js.org/#/contribution-guide
|
||||
[<img src="https://i.imgur.com/PXo25um.png" alt="drawing" height="50"/>](https://www.circadianrisk.com/)
|
||||
[<img src="https://i.imgur.com/AKGhtlh.png" alt="drawing"/>](https://lexense.com/)
|
||||
|
||||
|
||||
...and many more!
|
||||
|
||||
---
|
||||
|
@ -43,7 +43,7 @@ interface Skill {
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
interface Achivement {
|
||||
interface Achievement {
|
||||
readonly issuer: string;
|
||||
readonly name: string;
|
||||
}
|
||||
@ -64,7 +64,7 @@ const experiences: Experience[] = [
|
||||
{
|
||||
isCurrent: false,
|
||||
summary:
|
||||
"Full-stack developer working with Angular, Node and TypeScript. Working for the iShares platform. Emphasis on Dev-ops and developing the continous integration pipeline.",
|
||||
"Full-stack developer working with Angular, Node and TypeScript. Working for the iShares platform. Emphasis on Dev-ops and developing the continuous integration pipeline.",
|
||||
title: "Software Developer",
|
||||
endDate: {
|
||||
month: 11,
|
||||
@ -98,6 +98,7 @@ const experiences: Experience[] = [
|
||||
{
|
||||
isCurrent: false,
|
||||
summary:
|
||||
// cspell:disable-next-line
|
||||
"Develop web commerce platforms for various high profile clients.\n\nCreated a log analysis web application with the Play Framework in Java, incorporating Test Driven Development. It asynchronously uploads and processes large (2 GB) log files, and outputs meaningful results in context with the problem. \n\nAnalysis and development of the payment system infrastructure and user accounts section to be used by several clients of the company such as Waitrose, Tally Weijl, DJ Sports, Debenhams, Ann Summers, John Lewis and others.\n\nTechnologies used include WebSphere Commerce, Java, JavaScript and JSP.",
|
||||
title: "Java Developer",
|
||||
endDate: {
|
||||
@ -118,7 +119,7 @@ const education: Education[] = [
|
||||
{
|
||||
degree: "Master of Science (MSc)",
|
||||
fieldOfStudy: "Computer Science",
|
||||
notes: "Exam Results: 1st Class with Distinction, Dissertation: 1st Class with Distinction\n\nRelevant Courses: Java and C# Programming, Software Engineering, Artificial Intelligence, \nComputational Photography, Algorithmics, Architecture and Hardware.\n\nCreated a Windows 8 game in JavaScript for the dissertation. \n\nCreated an award-winning 3D stereoscopic game in C# using XNA.",
|
||||
notes: "Exam Results: 1st Class with Distinction, Dissertation: 1st Class with Distinction\n\nRelevant Courses: Java and C# Programming, Software Engineering, Artificial Intelligence, \nComputational Photography, Algorithms, Architecture and Hardware.\n\nCreated a Windows 8 game in JavaScript for the dissertation. \n\nCreated an award-winning 3D stereoscopic game in C# using XNA.",
|
||||
schoolName: "University College London",
|
||||
startDate: {
|
||||
year: 2012,
|
||||
@ -156,7 +157,7 @@ const skills: Skill[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const achievements: Achivement[] = [
|
||||
const achievements: Achievement[] = [
|
||||
{
|
||||
issuer: "Oracle",
|
||||
name: "Oracle Certified Expert",
|
||||
@ -165,7 +166,7 @@ const achievements: Achivement[] = [
|
||||
|
||||
class DocumentCreator {
|
||||
// tslint:disable-next-line: typedef
|
||||
public create([experiences, educations, skills, achivements]: [Experience[], Education[], Skill[], Achivement[]]): Document {
|
||||
public create([experiences, educations, skills, achievements]: [Experience[], Education[], Skill[], Achievement[]]): Document {
|
||||
const document = new Document({
|
||||
sections: [
|
||||
{
|
||||
@ -221,7 +222,7 @@ class DocumentCreator {
|
||||
this.createSubHeading("Skills"),
|
||||
this.createSkillList(skills),
|
||||
this.createSubHeading("Achievements"),
|
||||
...this.createAchivementsList(achivements),
|
||||
...this.createAchievementsList(achievements),
|
||||
this.createSubHeading("Interests"),
|
||||
this.createInterests("Programming, Technology, Music Production, Web Design, 3D Modelling, Dancing."),
|
||||
this.createHeading("References"),
|
||||
@ -318,8 +319,8 @@ class DocumentCreator {
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-any
|
||||
public createAchivementsList(achivements: any[]): Paragraph[] {
|
||||
return achivements.map(
|
||||
public createAchievementsList(achievements: any[]): Paragraph[] {
|
||||
return achievements.map(
|
||||
(achievement) =>
|
||||
new Paragraph({
|
||||
text: achievement.name,
|
||||
|
@ -53,17 +53,19 @@ const table = new Table({
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
config:[{
|
||||
reference: 'ref1',
|
||||
config: [
|
||||
{
|
||||
reference: "ref1",
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: '%1)',
|
||||
text: "%1)",
|
||||
start: 50,
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}]
|
||||
},
|
||||
styles: {
|
||||
default: {
|
||||
@ -185,10 +187,10 @@ const doc = new Document({
|
||||
rightTabStop: TabStopPosition.MAX,
|
||||
leftTabStop: 453.543307087,
|
||||
numbering: {
|
||||
reference: 'ref1',
|
||||
reference: "ref1",
|
||||
instance: 0,
|
||||
level: 0,
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -18,10 +18,15 @@ const doc = new Document({
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
children: ["Hello", new FootnoteReferenceRun(1)],
|
||||
children: ["Hello"],
|
||||
}),
|
||||
new FootnoteReferenceRun(1),
|
||||
new TextRun({
|
||||
children: [" World!", new FootnoteReferenceRun(2)],
|
||||
children: [" World!"],
|
||||
}),
|
||||
new FootnoteReferenceRun(2),
|
||||
new TextRun({
|
||||
children: [" GitHub!"],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -35,15 +40,17 @@ const doc = new Document({
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
children: ["Hello", new FootnoteReferenceRun(4)],
|
||||
children: ["Hello"],
|
||||
}),
|
||||
new FootnoteReferenceRun(4),
|
||||
new TextRun({
|
||||
children: [" World!", new FootnoteReferenceRun(5)],
|
||||
children: [" World!"],
|
||||
}),
|
||||
new FootnoteReferenceRun(5),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [new TextRun("Hello World"), new FootnoteReferenceRun(6)],
|
||||
children: [new TextRun("Hello World Again"), new FootnoteReferenceRun(6)],
|
||||
}),
|
||||
],
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Example on how to customise the look at feel using Styles
|
||||
// Example on how to customize the look at feel using Styles
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
|
@ -1,9 +1,21 @@
|
||||
// This demo shows how to create bookmarks then link to them with internal hyperlinks
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Bookmark, Document, Footer, HeadingLevel, InternalHyperlink, Packer, PageBreak, Paragraph, TextRun, PageReference } from "../build";
|
||||
import {
|
||||
Bookmark,
|
||||
Document,
|
||||
Footer,
|
||||
HeadingLevel,
|
||||
InternalHyperlink,
|
||||
Packer,
|
||||
PageBreak,
|
||||
Paragraph,
|
||||
TextRun,
|
||||
PageReference,
|
||||
} from "../build";
|
||||
|
||||
const LOREM_IPSUM =
|
||||
/* cspell:disable-next-line */
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi velit, convallis convallis scelerisque nec, faucibus nec leo. Phasellus at posuere mauris, tempus dignissim velit. Integer et tortor dolor. Duis auctor efficitur mattis. Vivamus ut metus accumsan tellus auctor sollicitudin venenatis et nibh. Cras quis massa ac metus fringilla venenatis. Proin rutrum mauris purus, ut suscipit magna consectetur id. Integer consectetur sollicitudin ante, vitae faucibus neque efficitur in. Praesent ultricies nibh lectus. Mauris pharetra id odio eget iaculis. Duis dictum, risus id pellentesque rutrum, lorem quam malesuada massa, quis ullamcorper turpis urna a diam. Cras vulputate metus vel massa porta ullamcorper. Etiam porta condimentum nulla nec tristique. Sed nulla urna, pharetra non tortor sed, sollicitudin molestie diam. Maecenas enim leo, feugiat eget vehicula id, sollicitudin vitae ante.";
|
||||
|
||||
const doc = new Document({
|
||||
|
@ -34,8 +34,7 @@ const doc = new Document({
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text:
|
||||
"Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
|
||||
text: "Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
],
|
||||
|
@ -1,9 +1,15 @@
|
||||
// Add image to table cell
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||
import { Document, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build";
|
||||
|
||||
const imageBase64Data = `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`;
|
||||
|
||||
const table = new Table({
|
||||
width: {
|
||||
size: 8640,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
rows: [
|
||||
new TableRow({
|
||||
children: [
|
||||
@ -17,7 +23,19 @@ const table = new Table({
|
||||
children: [],
|
||||
}),
|
||||
new TableCell({
|
||||
children: [],
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new ImageRun({
|
||||
data: Buffer.from(imageBase64Data, "base64"),
|
||||
transformation: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -27,7 +45,19 @@ const table = new Table({
|
||||
children: [],
|
||||
}),
|
||||
new TableCell({
|
||||
children: [],
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new ImageRun({
|
||||
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||
transformation: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new TableCell({
|
||||
children: [],
|
||||
|
@ -123,8 +123,7 @@ const noBorderTable = new Table({
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text:
|
||||
"Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
|
||||
text: "Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
],
|
||||
|
@ -43,8 +43,7 @@ const doc = new Document({
|
||||
style: "strong",
|
||||
}),
|
||||
new TextRun({
|
||||
text:
|
||||
" - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
|
||||
text: " - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -121,7 +121,7 @@ const doc = new Document({
|
||||
author: "Firstname Lastname",
|
||||
date: "2020-10-06T09:05:00Z",
|
||||
bold: false,
|
||||
}
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -4,7 +4,7 @@ import * as fs from "fs";
|
||||
import { Bookmark, Document, Packer, Paragraph, SimpleField, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
creator: 'Me',
|
||||
creator: "Me",
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
|
@ -13,11 +13,13 @@ const doc = new Document({
|
||||
},
|
||||
},
|
||||
children: [
|
||||
new Paragraph({ children: [
|
||||
new TextRun('This text will be in the first column.'),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun("This text will be in the first column."),
|
||||
new ColumnBreak(),
|
||||
new TextRun('This text will be in the second column.'),
|
||||
] }),
|
||||
new TextRun("This text will be in the second column."),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -27,7 +27,8 @@ import { Document, Packer, Paragraph, TextRun } from "docx";
|
||||
// Documents contain sections, you can have multiple sections per document, go here to learn more about sections
|
||||
// This simple example will only contain one section
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
children: [
|
||||
new Paragraph({
|
||||
@ -44,7 +45,8 @@ const doc = new Document({
|
||||
],
|
||||
}),
|
||||
],
|
||||
}],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Used to export the file into a .docx file
|
||||
@ -56,6 +58,7 @@ Packer.toBuffer(doc).then((buffer) => {
|
||||
```
|
||||
|
||||
<p align="center">
|
||||
<!-- cspell:disable-next-line -->
|
||||
<img alt="clippy the assistant" src="./clippy.png">
|
||||
</p>
|
||||
|
||||
|
@ -1,37 +1,39 @@
|
||||
* [Getting Started](/)
|
||||
- [Getting Started](/)
|
||||
|
||||
* [Examples](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||
- [Examples](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||
|
||||
* API
|
||||
- API
|
||||
|
||||
* [Documentation](https://docx.js.org/api/)
|
||||
- [Documentation](https://docx.js.org/api/)
|
||||
|
||||
* Usage
|
||||
- Usage
|
||||
|
||||
* [Document](usage/document.md)
|
||||
* [Sections](usage/sections.md)
|
||||
* [Paragraph](usage/paragraph.md)
|
||||
* [Text](usage/text.md)
|
||||
* [Image](usage/images.md)
|
||||
* [Headers & Footers](usage/headers-and-footers.md)
|
||||
* [Bullet Points](usage/bullet-points.md)
|
||||
* [Hyperlinks](usage/hyperlinks.md)
|
||||
* [Numbering](usage/numbering.md)
|
||||
* [Tables](usage/tables.md)
|
||||
* [Tab Stops](usage/tab-stops.md)
|
||||
* [Table of Contents](usage/table-of-contents.md)
|
||||
* [Page Numbers](usage/page-numbers.md)
|
||||
* [Change Tracking](usage/change-tracking.md)
|
||||
* [Math](usage/math.md)
|
||||
* [Text Frames](usage/text-frames.md)
|
||||
* Styling
|
||||
* [Styling with JS](usage/styling-with-js.md)
|
||||
* [Styling with XML](usage/styling-with-xml.md)
|
||||
* Exporting
|
||||
- [Document](usage/document.md)
|
||||
- [Sections](usage/sections.md)
|
||||
- [Paragraph](usage/paragraph.md)
|
||||
- [Text](usage/text.md)
|
||||
- [Image](usage/images.md)
|
||||
- [Headers & Footers](usage/headers-and-footers.md)
|
||||
- [Bullet Points](usage/bullet-points.md)
|
||||
- [Hyperlinks](usage/hyperlinks.md)
|
||||
- [Numbering](usage/numbering.md)
|
||||
- [Tables](usage/tables.md)
|
||||
- [Tab Stops](usage/tab-stops.md)
|
||||
- [Table of Contents](usage/table-of-contents.md)
|
||||
- [Page Numbers](usage/page-numbers.md)
|
||||
- [Change Tracking](usage/change-tracking.md)
|
||||
- [Math](usage/math.md)
|
||||
- [Text Frames](usage/text-frames.md)
|
||||
- Styling
|
||||
_ [Styling with JS](usage/styling-with-js.md)
|
||||
_ [Styling with XML](usage/styling-with-xml.md)
|
||||
|
||||
* [Packers](usage/packers.md)
|
||||
* Utility
|
||||
- Exporting
|
||||
|
||||
* [Convenience functions](usage/convenience-functions.md)
|
||||
- [Packers](usage/packers.md)
|
||||
|
||||
* [Contribution Guidelines](contribution-guidelines.md)
|
||||
- Utility
|
||||
|
||||
- [Convenience functions](usage/convenience-functions.md)
|
||||
|
||||
- [Contribution Guidelines](contribution-guidelines.md)
|
||||
|
@ -26,13 +26,15 @@ Please write good commit messages when making a commit: https://chris.beams.io/p
|
||||
|
||||
**Do not:**
|
||||
|
||||
<!-- cspell:disable -->
|
||||
```
|
||||
c // What?
|
||||
rtl // Adding acryonyms without explaining anything else is not helpful
|
||||
rtl // Adding acronyms without explaining anything else is not helpful
|
||||
works! // Glad its working, but the message is not helpful
|
||||
demo updated // Getting better, but capitalize the first letter
|
||||
Unesesary coment removed // Make sure to use correct spelling
|
||||
```
|
||||
<!-- cspell:enable -->
|
||||
|
||||
**Do**
|
||||
|
||||
@ -42,9 +44,9 @@ Unesesary coment removed // Make sure to use correct spelling
|
||||
public float(tableFloatOptions: ITableFloatOptions): Table
|
||||
```
|
||||
|
||||
## Delcariative API
|
||||
## Declarative API
|
||||
|
||||
Make sure the API is declarative, so no _method calling_ or _mutation_. This is a design decision, consistent with the rest of the project. There are benefits to delcariative code over other styles of code, explained here: https://dzone.com/articles/why-declarative-coding-makes-you-a-better-programm
|
||||
Make sure the API is declarative, so no _method calling_ or _mutation_. This is a design decision, consistent with the rest of the project. There are benefits to declarative code over other styles of code, explained here: https://dzone.com/articles/why-declarative-coding-makes-you-a-better-programm
|
||||
|
||||
**Do not:**
|
||||
|
||||
|
@ -37,7 +37,7 @@ sub-sublists, etc. Each level includes the following properties:
|
||||
numbers from each numbering level before this one. Thus a level
|
||||
text of `%d)` with a number format of `lowerLetter` would result in
|
||||
the sequence "a)", "b)", ...
|
||||
* and a few others, which you can see in the OXML spec section 17.9.6
|
||||
* and a few others, which you can see in the OOXML spec section 17.9.6
|
||||
|
||||
## Document-level bullets/numbering definitions (concrete)
|
||||
|
||||
|
@ -121,7 +121,7 @@ Add borders to a `Paragraph`. Good for making the `Paragraph` stand out
|
||||
| -------- | -------- | -------- |
|
||||
| color | `string` | Required |
|
||||
| space | `number` | Required |
|
||||
| value | `string` | Required |
|
||||
| style | `string` | Required |
|
||||
| size | `number` | Required |
|
||||
|
||||
**Example:**
|
||||
@ -135,13 +135,13 @@ const paragraph = new Paragraph({
|
||||
top: {
|
||||
color: "auto",
|
||||
space: 1,
|
||||
value: "single",
|
||||
style: "single",
|
||||
size: 6,
|
||||
},
|
||||
bottom: {
|
||||
color: "auto",
|
||||
space: 1,
|
||||
value: "single",
|
||||
style: "single",
|
||||
size: 6,
|
||||
},
|
||||
},
|
||||
|
@ -146,7 +146,7 @@ const doc = new Document({
|
||||
});
|
||||
```
|
||||
|
||||
**Note**: If you are using the `.headingX` or `.title` methods of paragraphs, you must make sure to define `HeadingX` or `Title` styles for these. Otherwise they'll show up unstyled :(. If you are using the `.bullet` or `.setNumbering` methods, you need to define a `ListParagraph` style or the numbers may not show up.
|
||||
**Note**: If you are using the `.headingX` or `.title` methods of paragraphs, you must make sure to define `HeadingX` or `Title` styles for these. Otherwise they'll show up un-styled :(. If you are using the `.bullet` or `.setNumbering` methods, you need to define a `ListParagraph` style or the numbers may not show up.
|
||||
|
||||
### Document defaults
|
||||
|
||||
@ -199,7 +199,7 @@ For these properties, the rules state the following conflict resolution in case
|
||||
|
||||
## Examples
|
||||
|
||||
### Declaritive styles
|
||||
### Declarative styles
|
||||
|
||||
Importing Images from file system path
|
||||
|
||||
|
1900
package-lock.json
generated
1900
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "7.4.0",
|
||||
"version": "7.4.1",
|
||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
@ -14,8 +14,9 @@
|
||||
"webpack": "rimraf ./build && webpack --config ./webpack.config.ts",
|
||||
"demo": "npm run build && npm run ts-node --skip-project ./demo",
|
||||
"typedoc": "rimraf ./build && typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
|
||||
"style": "prettier -l \"src/**/*.ts\"",
|
||||
"style": "prettier -l \"{src,scripts,demo}/**/*.{ts,html}\"",
|
||||
"style.fix": "npm run style -- --write",
|
||||
"cspell": "cspell \"{src,demo,docs,scripts}/**/*.{ts,scss,html,md}\" && cspell \"./*.*\"",
|
||||
"fix-types": "ts-node --skip-project scripts/types-absolute-fixer.ts",
|
||||
"e2e": "ts-node scripts/e2e.ts",
|
||||
"serve.docs": "cd docs && docsify serve",
|
||||
@ -73,6 +74,7 @@
|
||||
"@types/webpack": "^5.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"chai": "^3.5.0",
|
||||
"cspell": "^6.2.2",
|
||||
"docsify-cli": "^4.3.0",
|
||||
"glob": "^8.0.1",
|
||||
"jszip": "^3.1.5",
|
||||
|
@ -4,7 +4,8 @@ import * as sinon from "sinon";
|
||||
|
||||
import { File } from "@file/file";
|
||||
import { Footer, Header } from "@file/header";
|
||||
import { Paragraph } from "@file/paragraph";
|
||||
import { ImageRun, Paragraph } from "@file/paragraph";
|
||||
import * as convenienceFunctions from "@util/convenience-functions";
|
||||
|
||||
import { Compiler } from "./next-compiler";
|
||||
|
||||
@ -15,6 +16,14 @@ describe("Compiler", () => {
|
||||
compiler = new Compiler();
|
||||
});
|
||||
|
||||
before(() => {
|
||||
sinon.stub(convenienceFunctions, "uniqueId").callsFake(() => "test");
|
||||
});
|
||||
|
||||
after(() => {
|
||||
(convenienceFunctions.uniqueId as sinon.SinonStub).restore();
|
||||
});
|
||||
|
||||
describe("#compile()", () => {
|
||||
it("should pack all the content", async function () {
|
||||
this.timeout(99999999);
|
||||
@ -111,18 +120,38 @@ describe("Compiler", () => {
|
||||
const spy = sinon.spy(compiler["formatter"], "format");
|
||||
|
||||
compiler.compile(file);
|
||||
expect(spy.callCount).to.equal(12);
|
||||
expect(spy.callCount).to.equal(13);
|
||||
});
|
||||
|
||||
it("should work with media datas", () => {
|
||||
// This test is required because before, there was a case where Document was formatted twice, which was inefficient
|
||||
// This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
|
||||
const paragraph = new Paragraph("");
|
||||
const file = new File({
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
children: [paragraph],
|
||||
headers: {
|
||||
default: new Header({
|
||||
children: [new Paragraph("test")],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer({
|
||||
children: [new Paragraph("test")],
|
||||
}),
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new ImageRun({
|
||||
data: Buffer.from("", "base64"),
|
||||
transformation: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -6,7 +6,7 @@ import { File } from "@file/file";
|
||||
import { Formatter } from "../formatter";
|
||||
import { ImageReplacer } from "./image-replacer";
|
||||
import { NumberingReplacer } from "./numbering-replacer";
|
||||
import { PrettityType } from "./packer";
|
||||
import { PrettifyType } from "./packer";
|
||||
|
||||
interface IXmlifyedFile {
|
||||
readonly data: string;
|
||||
@ -44,7 +44,7 @@ export class Compiler {
|
||||
this.numberingReplacer = new NumberingReplacer();
|
||||
}
|
||||
|
||||
public compile(file: File, prettifyXml?: boolean | PrettityType): JSZip {
|
||||
public compile(file: File, prettifyXml?: boolean | PrettifyType): JSZip {
|
||||
const zip = new JSZip();
|
||||
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
|
||||
const map = new Map<string, IXmlifyedFile | IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
|
||||
@ -67,7 +67,7 @@ export class Compiler {
|
||||
return zip;
|
||||
}
|
||||
|
||||
private xmlifyFile(file: File, prettify?: boolean | PrettityType): IXmlifyedFileMapping {
|
||||
private xmlifyFile(file: File, prettify?: boolean | PrettifyType): IXmlifyedFileMapping {
|
||||
const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1;
|
||||
|
||||
const documentXmlData = xml(
|
||||
@ -406,12 +406,7 @@ export class Compiler {
|
||||
path: "word/settings.xml",
|
||||
},
|
||||
Comments: {
|
||||
data: (() => {
|
||||
if (!file.Comments) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = xml(
|
||||
data: xml(
|
||||
this.formatter.format(file.Comments, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
@ -423,9 +418,7 @@ export class Compiler {
|
||||
encoding: "UTF-8",
|
||||
},
|
||||
},
|
||||
);
|
||||
return data;
|
||||
})(),
|
||||
),
|
||||
path: "word/comments.xml",
|
||||
},
|
||||
};
|
||||
|
@ -5,7 +5,7 @@ import { Compiler } from "./next-compiler";
|
||||
/**
|
||||
* Use blanks to prettify
|
||||
*/
|
||||
export enum PrettityType {
|
||||
export enum PrettifyType {
|
||||
NONE = "",
|
||||
WITH_2_BLANKS = " ",
|
||||
WITH_4_BLANKS = " ",
|
||||
@ -13,7 +13,7 @@ export enum PrettityType {
|
||||
}
|
||||
|
||||
export class Packer {
|
||||
public static async toBuffer(file: File, prettify?: boolean | PrettityType): Promise<Buffer> {
|
||||
public static async toBuffer(file: File, prettify?: boolean | PrettifyType): Promise<Buffer> {
|
||||
const zip = this.compiler.compile(file, prettify);
|
||||
const zipData = await zip.generateAsync({
|
||||
type: "nodebuffer",
|
||||
@ -24,7 +24,7 @@ export class Packer {
|
||||
return zipData;
|
||||
}
|
||||
|
||||
public static async toBase64String(file: File, prettify?: boolean | PrettityType): Promise<string> {
|
||||
public static async toBase64String(file: File, prettify?: boolean | PrettifyType): Promise<string> {
|
||||
const zip = this.compiler.compile(file, prettify);
|
||||
const zipData = await zip.generateAsync({
|
||||
type: "base64",
|
||||
@ -35,7 +35,7 @@ export class Packer {
|
||||
return zipData;
|
||||
}
|
||||
|
||||
public static async toBlob(file: File, prettify?: boolean | PrettityType): Promise<Blob> {
|
||||
public static async toBlob(file: File, prettify?: boolean | PrettifyType): Promise<Blob> {
|
||||
const zip = this.compiler.compile(file, prettify);
|
||||
const zipData = await zip.generateAsync({
|
||||
type: "blob",
|
||||
|
@ -41,6 +41,7 @@ export interface IPropertiesOptions {
|
||||
|
||||
// <xs:element name="coreProperties" type="CT_CoreProperties"/>
|
||||
|
||||
/* cSpell:disable */
|
||||
// <xs:complexType name="CT_CoreProperties">
|
||||
// <xs:all>
|
||||
// <xs:element name="category" minOccurs="0" maxOccurs="1" type="xs:string"/>
|
||||
@ -60,6 +61,7 @@ export interface IPropertiesOptions {
|
||||
// <xs:element name="version" minOccurs="0" maxOccurs="1" type="xs:string"/>
|
||||
// </xs:all>
|
||||
// </xs:complexType>
|
||||
/* cSpell:enable */
|
||||
|
||||
export class CoreProperties extends XmlComponent {
|
||||
constructor(options: Omit<IPropertiesOptions, "sections">) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { XmlAttributeComponent } from "@file/xml-components";
|
||||
|
||||
/* cSpell:disable */
|
||||
export interface IDocumentAttributesProperties {
|
||||
readonly wpc?: string;
|
||||
readonly mc?: string;
|
||||
@ -41,6 +42,7 @@ export interface IDocumentAttributesProperties {
|
||||
readonly w16sdtdh?: string;
|
||||
readonly w16se?: string;
|
||||
}
|
||||
/* cSpell:enable */
|
||||
|
||||
export class DocumentAttributes extends XmlAttributeComponent<IDocumentAttributesProperties> {
|
||||
protected readonly xmlKeys = {
|
||||
|
@ -71,10 +71,7 @@ export class File {
|
||||
},
|
||||
);
|
||||
|
||||
if (options.comments) {
|
||||
this.comments = new Comments(options.comments);
|
||||
}
|
||||
|
||||
this.comments = new Comments(options.comments ?? { children: [] });
|
||||
this.fileRelationships = new Relationships();
|
||||
this.customProperties = new CustomProperties(options.customProperties ?? []);
|
||||
this.appProperties = new AppProperties();
|
||||
|
@ -1,7 +1,7 @@
|
||||
export * from "./math-accent-character";
|
||||
export * from "./math-base";
|
||||
export * from "./math-limit-location";
|
||||
export * from "./math-naray-properties";
|
||||
export * from "./math-n-ary-properties";
|
||||
export * from "./math-sub-script";
|
||||
export * from "./math-sum";
|
||||
export * from "./math-super-script";
|
||||
|
@ -2,14 +2,14 @@ import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathNArayProperties } from "./math-naray-properties";
|
||||
import { MathNAryProperties } from "./math-n-ary-properties";
|
||||
|
||||
describe("MathNArayProperties", () => {
|
||||
describe("MathNAryProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathNArayProperties with correct root key", () => {
|
||||
const mathNArayProperties = new MathNArayProperties("∑", true, true);
|
||||
it("should create a MathNAryProperties with correct root key", () => {
|
||||
const mathNAryProperties = new MathNAryProperties("∑", true, true);
|
||||
|
||||
const tree = new Formatter().format(mathNArayProperties);
|
||||
const tree = new Formatter().format(mathNAryProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:naryPr": [
|
||||
{
|
||||
@ -31,9 +31,9 @@ describe("MathNArayProperties", () => {
|
||||
});
|
||||
|
||||
it("should add super-script hide attributes", () => {
|
||||
const mathNArayProperties = new MathNArayProperties("∑", false, true);
|
||||
const mathNAryProperties = new MathNAryProperties("∑", false, true);
|
||||
|
||||
const tree = new Formatter().format(mathNArayProperties);
|
||||
const tree = new Formatter().format(mathNAryProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:naryPr": [
|
||||
{
|
||||
@ -62,9 +62,9 @@ describe("MathNArayProperties", () => {
|
||||
});
|
||||
|
||||
it("should add sub-script hide attributes", () => {
|
||||
const mathNArayProperties = new MathNArayProperties("∑", true, false);
|
||||
const mathNAryProperties = new MathNAryProperties("∑", true, false);
|
||||
|
||||
const tree = new Formatter().format(mathNArayProperties);
|
||||
const tree = new Formatter().format(mathNAryProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:naryPr": [
|
||||
{
|
||||
@ -93,9 +93,9 @@ describe("MathNArayProperties", () => {
|
||||
});
|
||||
|
||||
it("should add both super-script and sub-script hide attributes", () => {
|
||||
const mathNArayProperties = new MathNArayProperties("∑", false, false);
|
||||
const mathNAryProperties = new MathNAryProperties("∑", false, false);
|
||||
|
||||
const tree = new Formatter().format(mathNArayProperties);
|
||||
const tree = new Formatter().format(mathNAryProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:naryPr": [
|
||||
{
|
@ -6,7 +6,7 @@ import { MathLimitLocation } from "./math-limit-location";
|
||||
import { MathSubScriptHide } from "./math-sub-script-hide";
|
||||
import { MathSuperScriptHide } from "./math-super-script-hide";
|
||||
|
||||
export class MathNArayProperties extends XmlComponent {
|
||||
export class MathNAryProperties extends XmlComponent {
|
||||
constructor(accent: string, hasSuperScript: boolean, hasSubScript: boolean) {
|
||||
super("m:naryPr");
|
||||
|
@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "./math-base";
|
||||
import { MathNArayProperties } from "./math-naray-properties";
|
||||
import { MathNAryProperties } from "./math-n-ary-properties";
|
||||
import { MathSubScriptElement } from "./math-sub-script";
|
||||
import { MathSuperScriptElement } from "./math-super-script";
|
||||
|
||||
@ -17,7 +17,7 @@ export class MathSum extends XmlComponent {
|
||||
constructor(options: IMathSumOptions) {
|
||||
super("m:nary");
|
||||
|
||||
this.root.push(new MathNArayProperties("∑", !!options.superScript, !!options.subScript));
|
||||
this.root.push(new MathNAryProperties("∑", !!options.superScript, !!options.subScript));
|
||||
|
||||
if (!!options.subScript) {
|
||||
this.root.push(new MathSubScriptElement(options.subScript));
|
||||
|
@ -27,6 +27,7 @@ export enum RelativeVerticalPosition {
|
||||
}
|
||||
|
||||
export interface ITableFloatOptions {
|
||||
/* cSpell:disable */
|
||||
/**
|
||||
* Specifies the horizontal anchor or the base object from which the horizontal positioning in the
|
||||
* tblpX or tblpXSpec attribute should be determined.
|
||||
@ -35,6 +36,7 @@ export interface ITableFloatOptions {
|
||||
* text - relative to the vertical edge of the text margin for the column in which the anchor paragraph is located
|
||||
* If omitted, the value is assumed to be page.
|
||||
*/
|
||||
/* cSpell:enable */
|
||||
readonly horizontalAnchor?: TableAnchorType;
|
||||
|
||||
/**
|
||||
@ -90,25 +92,25 @@ export interface ITableFloatOptions {
|
||||
readonly relativeVerticalPosition?: RelativeVerticalPosition;
|
||||
|
||||
/**
|
||||
* Specifies the minimun distance to be maintained between the table and the top of text in the paragraph
|
||||
* Specifies the minimum distance to be maintained between the table and the top of text in the paragraph
|
||||
* below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||
*/
|
||||
readonly bottomFromText?: number | string;
|
||||
|
||||
/**
|
||||
* Specifies the minimun distance to be maintained between the table and the bottom edge of text in the paragraph
|
||||
* Specifies the minimum distance to be maintained between the table and the bottom edge of text in the paragraph
|
||||
* above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||
*/
|
||||
readonly topFromText?: number | string;
|
||||
|
||||
/**
|
||||
* Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph
|
||||
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
|
||||
* to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||
*/
|
||||
readonly leftFromText?: number | string;
|
||||
|
||||
/**
|
||||
* Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph
|
||||
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
|
||||
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||
*/
|
||||
readonly rightFromText?: number | string;
|
||||
|
@ -13,7 +13,7 @@ describe("Deleted Page", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Delted NumberOfPages", () => {
|
||||
describe("Deleted NumberOfPages", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("uses the font name for both ascii and hAnsi", () => {
|
||||
const tree = new Formatter().format(new DeletedNumberOfPages());
|
||||
|
@ -13,8 +13,8 @@ export function convertToXmlComponent(element: XmlElement): ImportedXmlComponent
|
||||
case undefined:
|
||||
case "element":
|
||||
const xmlComponent = new ImportedXmlComponent(element.name as string, element.attributes);
|
||||
const childElments = element.elements || [];
|
||||
for (const childElm of childElments) {
|
||||
const childElements = element.elements || [];
|
||||
for (const childElm of childElements) {
|
||||
const child = convertToXmlComponent(childElm);
|
||||
if (child !== undefined) {
|
||||
xmlComponent.push(child);
|
||||
|
@ -141,12 +141,12 @@ export class ImportDotx {
|
||||
}
|
||||
|
||||
private async addRelationshipToWrapper(
|
||||
relationhipFile: IRelationshipFileInfo,
|
||||
relationshipFile: IRelationshipFileInfo,
|
||||
zipContent: JSZip,
|
||||
wrapper: HeaderWrapper | FooterWrapper,
|
||||
media: Media,
|
||||
): Promise<void> {
|
||||
const refFile = zipContent.files[`word/_rels/${relationhipFile.target}.rels`];
|
||||
const refFile = zipContent.files[`word/_rels/${relationshipFile.target}.rels`];
|
||||
|
||||
if (!refFile) {
|
||||
return;
|
||||
|
@ -4,13 +4,13 @@ import { convertInchesToTwip, convertMillimetersToTwip, uniqueId, uniqueNumericI
|
||||
|
||||
describe("Utility", () => {
|
||||
describe("#convertMillimetersToTwip", () => {
|
||||
it("should call the underlying header's addChildElement for Paragraph", () => {
|
||||
it("should convert millimeters to TWIP", () => {
|
||||
expect(convertMillimetersToTwip(1000)).to.equal(56692);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#convertInchesToTwip", () => {
|
||||
it("should call the underlying header's addChildElement", () => {
|
||||
it("should convert inches to TWIP", () => {
|
||||
expect(convertInchesToTwip(1)).to.equal(1440);
|
||||
expect(convertInchesToTwip(0.5)).to.equal(720);
|
||||
expect(convertInchesToTwip(0.25)).to.equal(360);
|
||||
|
@ -73,6 +73,7 @@ describe("values", () => {
|
||||
it("should throw on invalid values", () => {
|
||||
expect(() => shortHexNumber("11")).to.throw();
|
||||
expect(() => shortHexNumber("112233")).to.throw();
|
||||
/* cspell:disable-next-line */
|
||||
expect(() => shortHexNumber("FFFG")).to.throw();
|
||||
});
|
||||
});
|
||||
|
@ -208,6 +208,7 @@ export const pointMeasureValue = unsignedDecimalNumber;
|
||||
//
|
||||
// http://www.datypic.com/sc/xsd/t-xsd_dateTime.html
|
||||
// The type xsd:dateTime represents a specific date and time in the format
|
||||
/* cspell:disable-next-line */
|
||||
// CCYY-MM-DDThh:mm:ss.sss, which is a concatenation of the date and time forms,
|
||||
// separated by a literal letter "T". All of the same rules that apply to the date
|
||||
// and time types are applicable to xsd:dateTime as well.
|
||||
|
Reference in New Issue
Block a user