feat: Added NumberedItemReference (#3042)
* feat: Added NumberedItemReference * Fix linting * ts-ignore until TypeScript upgrade --------- Co-authored-by: Alexander Nortung <alexander.nortung@oakdigital.dk>
This commit is contained in:
@ -16,12 +16,10 @@ const chapter1 = new Paragraph({
|
||||
children: [
|
||||
new Bookmark({
|
||||
id: "anchorForChapter1",
|
||||
children: [
|
||||
new TextRun("Chapter 1"),
|
||||
],
|
||||
children: [new TextRun("Chapter 1")],
|
||||
}),
|
||||
],
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
Then you can create an hyperlink pointing to that bookmark with an `InternalHyperLink`:
|
||||
@ -35,20 +33,32 @@ const link = new InternalHyperlink({
|
||||
}),
|
||||
],
|
||||
anchor: "anchorForChapter1",
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
### Page reference
|
||||
|
||||
You can also get the page number of the bookmark by creating a page reference to it:
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
children: [
|
||||
new TextRun("Chapter 1 can be seen on page "),
|
||||
new PageReference("anchorForChapter1"),
|
||||
],
|
||||
children: [new TextRun("Chapter 1 can be seen on page "), new PageReference("anchorForChapter1")],
|
||||
});
|
||||
```
|
||||
|
||||
### Numbered item reference
|
||||
|
||||
You can also create cross references for numbered items with `NumberedItemReference`.
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
children: [new TextRun("See Paragraph "), new NumberedItemReference("anchorForParagraph1", "1.1")],
|
||||
});
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> The `NumberedItemReference` currently needs a cached value (in this case `1.1`)
|
||||
|
||||
## External
|
||||
|
||||
To create an external hyperlink you just need to specify the url and the text of the link, then add it to a paragraph:
|
||||
@ -69,7 +79,6 @@ const paragraph = new Paragraph({
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Styling hyperlinks
|
||||
|
||||
It is possible to set the style of the text of both internal and external hyperlinks. This can be done applying run formatting on any of the `TextRun` children of the hyperlink. Use the `style: "Hyperlink"` property to show the default link styles, which can be combined with any other style.
|
||||
|
Reference in New Issue
Block a user