Automatic bookmark generation
Automatically generates bookmarks for all heading paragraphs in the document, using the heading text as the bookmark name.
(function () {
let doc = Api.GetDocument();
let headingParagraphs = doc.GetAllHeadingParagraphs();
let bookmarkCounter = 1;
headingParagraphs.forEach((paragraph, index) => {
let headingText = paragraph.GetText().replace(/\s+/g, "_");
let bookmarkName = `Bookmark_${headingText}_${bookmarkCounter}`;
let range = paragraph.GetRange();
range.AddBookmark(bookmarkName);
bookmarkCounter++;
});
})();
Methods used: GetDocument, GetAllHeadingParagraphs, GetText, GetRange, AddBookmark