Files
docx-js/docs/usage/text.md

164 lines
3.3 KiB
Markdown
Raw Normal View History

2019-08-06 18:27:00 +01:00
# Text Runs
!> TextRuns requires an understanding of [Paragraphs](usage/paragraph.md).
2018-08-04 03:28:27 +01:00
2019-08-03 13:42:24 +01:00
You can add multiple `text runs` in `Paragraphs`. This is the most verbose way of writing a `Paragraph` but it is also the most flexible:
2018-08-04 03:28:27 +01:00
```ts
2019-08-06 18:27:00 +01:00
import { Paragraph, TextRun } from "docx";
2019-08-03 13:42:24 +01:00
const paragraph = new Paragraph({
2019-08-06 18:27:00 +01:00
children: [new TextRun("My awesome text here for my university dissertation"), new TextRun("Foo Bar")],
2019-08-03 13:42:24 +01:00
});
2018-08-04 03:28:27 +01:00
```
Text objects have methods inside which changes the way the text is displayed.
## Typographical Emphasis
More info [here](https://english.stackexchange.com/questions/97081/what-is-the-typography-term-which-refers-to-the-usage-of-bold-italics-and-unde)
### Bold
```ts
2019-08-06 18:27:00 +01:00
const text = new TextRun({
text: "Foo Bar",
bold: true,
});
2018-08-04 03:28:27 +01:00
```
### Italics
```ts
2019-08-06 18:27:00 +01:00
const text = new TextRun({
text: "Foo Bar",
italics: true,
});
2018-08-04 03:28:27 +01:00
```
### Underline
2019-08-06 18:27:00 +01:00
Underline has a few options
#### Options
| Property | Type | Notes | Possible Values |
| -------- | --------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type | `UnderlineType` | Optional | SINGLE, WORD, DOUBLE, THICK, DOTTED, DOTTEDHEAV, DASH, DASHEDHEAV, DASHLONG, DASHLONGHEAV, DOTDASH, DASHDOTHEAVY, DOTDOTDAS, DASHDOTDOTHEAVY, WAVE, WAVYHEAVY, WAVYDOUBLE |
| color | `string` | Optional | Color Hex values |
**Example:**
```ts
2019-08-06 18:27:00 +01:00
const text = new TextRun({
text: "and then underlined ",
underline: {
type: UnderlineType.DOUBLE,
color: "990011",
},
});
```
To do a simple vanilla underline:
```ts
const text = new TextRun({
text: "and then underlined ",
underline: {},
});
2018-08-04 03:28:27 +01:00
```
2020-05-22 12:32:40 +08:00
### Emphasis Mark
```ts
const text = new TextRun({
text: "and then emphasis mark",
emphasisMark: {},
});
```
2020-10-28 01:05:31 +00:00
### Shading and Highlighting
```ts
const text = new TextRun({
text: "shading",
shading: {
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
color: "00FFFF",
fill: "FF0000",
},
});
```
```ts
const text = new TextRun({
text: "highlighting",
highlight: "yellow",
});
```
2018-08-04 03:28:27 +01:00
### Strike through
```ts
2020-10-28 01:05:31 +00:00
const text = new TextRun({
text: "strike",
strike: true,
});
2018-08-04 03:28:27 +01:00
```
### Double strike through
```ts
2020-10-28 01:05:31 +00:00
const text = new TextRun({
text: "doubleStrike",
doubleStrike: true,
});
2018-08-04 03:28:27 +01:00
```
### Superscript
```ts
2020-10-28 01:05:31 +00:00
const text = new TextRun({
text: "superScript",
superScript: true,
});
2018-08-04 03:28:27 +01:00
```
### Subscript
```ts
2020-10-28 01:05:31 +00:00
const text = new TextRun({
text: "subScript",
subScript: true,
});
2018-08-04 03:28:27 +01:00
```
### All Capitals
```ts
2020-10-28 01:05:31 +00:00
const text = new TextRun({
text: "allCaps",
allCaps: true,
});
2018-08-04 03:28:27 +01:00
```
### Small Capitals
```ts
2020-10-28 01:05:31 +00:00
const text = new TextRun({
text: "smallCaps",
smallCaps: true,
});
2018-08-04 03:28:27 +01:00
```
## Break
Sometimes you would want to put text underneath another line of text but inside the same paragraph.
```ts
2020-10-28 01:05:31 +00:00
const text = new TextRun({
text: "break",
break: true,
});
2018-08-04 03:28:27 +01:00
```