From bb8ac8b9d83ed83a0fb89ccced94bd07a18490b2 Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Tue, 18 May 2021 17:15:29 +0300 Subject: [PATCH 1/2] Fix broken links in documentation. --- docs/usage/bullet-points.md | 8 ++++---- docs/usage/paragraph.md | 4 ++-- docs/usage/symbols.md | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/usage/bullet-points.md b/docs/usage/bullet-points.md index 102df87673..47e2044c40 100644 --- a/docs/usage/bullet-points.md +++ b/docs/usage/bullet-points.md @@ -12,14 +12,14 @@ const doc = new Document({ new Paragraph({ text: "Bullet points", bullet: { - level: 0 //How deep you want the bullet to be - } + level: 0 //How deep you want the bullet to be + } }), new Paragraph({ text: "Are awesome", bullet: { - level: 0 - } + level: 0 + } }) ], }]; diff --git a/docs/usage/paragraph.md b/docs/usage/paragraph.md index 79375a21b4..0176a43793 100644 --- a/docs/usage/paragraph.md +++ b/docs/usage/paragraph.md @@ -2,7 +2,7 @@ > Everything (text, images, graphs etc) in OpenXML is organized in paragraphs. -!> Paragraphs requires an understanding of [Sections](sections.md). +!> Paragraphs requires an understanding of [Sections](usage/sections.md). You can create `Paragraphs` in the following ways: @@ -16,7 +16,7 @@ const paragraph = new Paragraph("Short hand Hello World"); ### Children Method -This method is useful for adding different [text](text.md) with different styles, [symbols](symbols.md), or adding [images](images.md) inline. +This method is useful for adding different [text](usage/text.md) with different styles, [symbols](usage/symbols.md), or adding [images](usage/images.md) inline. ```ts const paragraph = new Paragraph({ diff --git a/docs/usage/symbols.md b/docs/usage/symbols.md index 8b283e9da7..08cf4ffa31 100644 --- a/docs/usage/symbols.md +++ b/docs/usage/symbols.md @@ -1,8 +1,8 @@ # Symbol Runs -!> SymbolRuns require an understanding of [Paragraphs](paragraph.md). +!> SymbolRuns require an understanding of [Paragraphs](usage/paragraph.md). -You can add multiple `symbol runs` in `Paragraphs` along with [text runs](text.md) using the Paragraph's `children` property. +You can add multiple `symbol runs` in `Paragraphs` along with [text runs](usage/text.md) using the Paragraph's `children` property. ```ts import { Paragraph, TextRun, SymbolRun } from "docx"; @@ -50,4 +50,4 @@ const symbol = new SymbolRun({ }); ``` -See the [text run](text.md) documentation for more info. +See the [text run](usage/text.md) documentation for more info. From d527013451fd7d92ccc8c8911d0502528a6f7aad Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Tue, 18 May 2021 17:16:10 +0300 Subject: [PATCH 2/2] Update outdated docs to show current usage --- docs/usage/page-numbers.md | 51 +++++++++++++++++++++++--------------- docs/usage/tables.md | 6 ----- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/docs/usage/page-numbers.md b/docs/usage/page-numbers.md index 45348385bb..377a453e39 100644 --- a/docs/usage/page-numbers.md +++ b/docs/usage/page-numbers.md @@ -5,35 +5,49 @@ ?> **Note:** This feature only works on Headers and Footers ```ts -doc.Header.createParagraph().addRun(new TextRun("Page Number: ").pageNumber()).addRun(new TextRun("to ").numberOfTotalPages()); +new Paragraph({ + children: [ + new TextRun({ + children: ["Page #: ", PageNumber.CURRENT], + }) + ] +}) ``` ## Current page number -To get the current page number, call the `.pageNumber()` method on a `TextRun`. Then add the newly created `TextRun` into a paragraph - ```ts -pageNumber(); +PageNumber.CURRENT ``` For example: ```ts -const currentPageRun = new TextRun("Current Page Number: ").pageNumber(); -paragraph.addRun(currentPageRun); +new Paragraph({ + children: [ + new TextRun({ + children: ["Page Number ", PageNumber.CURRENT], + }) + ] +}) ``` ## Total number of pages ```ts -numberOfTotalPages(); +PageNumber.TOTAL_PAGES ``` For example: ```ts -const lastPage = new TextRun("Total Page Number: ").numberOfTotalPages(); -paragraph.addRun(lastPage); +new Paragraph({ + children: [ + new TextRun({ + children: ["Total Pages Number: ", PageNumber.TOTAL_PAGES], + }) + ] +}) ``` @@ -42,17 +56,14 @@ paragraph.addRun(lastPage); You can combine the two to get "Page 2 of 10" effect: ```ts -const currentPageRun = new TextRun("Page ").pageNumber(); -const lastPage = new TextRun("of ").numberOfTotalPages(); - -paragraph.addRun(currentPageRun); -paragraph.addRun(lastPage); -``` - -Or: - -```ts -doc.Header.createParagraph().addRun(new TextRun("Page ").pageNumber()).addRun(new TextRun("of ").numberOfTotalPages()); +new Paragraph({ + children: [ + new TextRun("My awesome text here for my university dissertation. ") + new TextRun({ + children: ["Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES], + }) + ] +}) ``` ## Examples diff --git a/docs/usage/tables.md b/docs/usage/tables.md index 81183b60b4..450d05e9b7 100644 --- a/docs/usage/tables.md +++ b/docs/usage/tables.md @@ -237,12 +237,6 @@ const cell = new TableCell({ | NIL | is considered as zero | | PCT | percent of table width | -#### Example - -```ts -cell.Properties.setWidth(100, WidthType.DXA); -``` - ### Nested Tables To have a table within a table, simply add it in the `children` block of a `table cell`: