diff --git a/.gitignore b/.gitignore index 53f1416525..4f8777b466 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,10 @@ node_modules build build-tests +# Documentation +docs/api/ +docs/.nojekyll + # VSCode .vscode/* !.vscode/settings.json diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000000..04c68bd24a --- /dev/null +++ b/docs/README.md @@ -0,0 +1,15 @@ +

+ clippy the assistant +

+ +

+ Easily generate .docx files with JS/TS. +

+ +--- + +# Welcome + +--- + +Made with 💖 diff --git a/docs/_sidebar.md b/docs/_sidebar.md new file mode 100644 index 0000000000..307ebffcfc --- /dev/null +++ b/docs/_sidebar.md @@ -0,0 +1,25 @@ +* Getting Started + + * [Quick Start](quick-start.md) + +* API + + * [Documentation](/api) + +* Usage + + * [Document](usage/document.md) + * [Paragraph](usage/paragraph.md) + * [Text](usage/text.md) + * [Image](usage/images.md) + * [Headers & Footers](usage/header-and-footers.md) + * [Bullet Points](usage/bullet-points.md) + * [Tab Stops](usage/tab-stops.md) + * [Styling](usage/styling.md) + +* Exporting + + * [Packers](usage/packers.md) + +* [Examples](usage/examples.md) + diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000000..9ff9bd26a2 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,23 @@ + + + + + docx - Generate .docx documents with JavaScript + + + + + + +
+ + + + diff --git a/docs/quick-start.md b/docs/quick-start.md new file mode 100644 index 0000000000..05cf8c1fd0 --- /dev/null +++ b/docs/quick-start.md @@ -0,0 +1 @@ +# Quick Start diff --git a/docs/usage/paragraph.md b/docs/usage/paragraph.md new file mode 100644 index 0000000000..532ca455e9 --- /dev/null +++ b/docs/usage/paragraph.md @@ -0,0 +1,105 @@ +# Paragraph +> Everything (text, images, graphs etc) in OpenXML is organised in paragraphs. You can add more text to the paragraph by doing this: + +```js +var paragraph = new docx.Paragraph(), +``` + +```js +var text = new docx.TextRun('Lorem Ipsum Foo Bar'); +var paragraph = new docx.Paragraph(); +paragraph.addRun(text); +``` + +```js +var paragraph = new docx.Paragraph("Short hand notation for adding text."); +``` + +After you create the paragraph, you must add the paragraph into the `document`: + +```js +doc.addParagraph(paragraph); +``` + +## Styles + +To create styles, please refer to the styling Wiki: https://github.com/dolanmiu/docx/wiki/Styling + +![Word 2013 Styles menu](http://content.gcflearnfree.org/topics/233/style_apply_choose.png "Word 2013 Styles menu") + +### Heading1 - Heading5 + +```js +paragraph.heading1(); +paragraph.heading2(); +paragraph.heading3(); +paragraph.heading4(); +paragraph.heading5(); +``` + +### Title + +```js +paragraph.title(); +``` + +## Text Alignment + +To change the text alignment of a paragraph, for center, left, right or justified: + +```js +paragraph.center(); +``` + +```js +paragraph.left(); +``` +```js +paragraph.right(); +``` + +```js +paragraph.justified(); +``` + +### Example + +```js +paragraph.heading1().center(); +``` + +The above will create a `heading 1` which is `centered`. + +## Thematic Break +To add a break in the page, simply add `.thematicBreak()` on a paragraph: + +```js +var paragraph = new docx.Paragraph("Amazing Heading").heading1().thematicBreak(); +``` + +The above example will create a heading with a page break directly under it. + +## Page Break + +To move to a new page (insert a page break), simply add `.pageBreak()` on a paragraph: + +```js +var paragraph = new docx.Paragraph("Amazing Heading").heading1().pageBreak(); +``` + +The above example will create a heading and start a new page immediately afterwards. + +### Page break before: +This option (available in word) will make sure that the paragraph will start on a new page (if it's not already on a new page). + +```js +var paragraph = new docx.Paragraph("Hello World on another page").pageBreakBefore(); +``` + +![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/demo15.js + +## Page break control + +Paragraphs have `.keepLines()` and `.keepNext()` methods that allow restricting page breaks within and between paragraphs. See [this Microsoft article](https://support.office.com/en-us/article/Keep-lines-and-paragraphs-together-d72af534-926f-4c4b-830a-abfc2daa3bfa) for more details) diff --git a/package.json b/package.json index 2eaf10efab..9e292bcb1c 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "tsc": "rimraf ./build && tsc -p .", "webpack": "rimraf ./build && webpack", "demo": "npm run build && node ./demo", - "typedoc": "typedoc --out docs/ src/ --module commonjs --target ES6 --disableOutputCheck --excludePrivate --externalPattern \"**/*.spec.ts\"", + "typedoc": "typedoc --out docs/api/ src/ --module commonjs --target ES6 --disableOutputCheck --excludePrivate --externalPattern \"**/*.spec.ts\"", "style": "prettier -l \"src/**/*.ts\"", "style.fix": "prettier \"src/**/*.ts\" --write", "fix-types": "node types-absolute-fixer.js"