// add a link to a bookmark

import { CreateDocx, OptionsLink, WordFragment } from "../../../build";
import * as fs from "fs";

const docx = new CreateDocx();

const link: OptionsLink = {
    link: "#bookmark_name",
    text: "Link to a bookmark",
};
docx.addLink(link);

// add a bookmark in a new page
docx.addBreak("page");
// create a bookmark WordFragment
const wordFragmentBookmark = new WordFragment();
wordFragmentBookmark.addBookmark("bookmark_name");

// create a text WordFragment
const wordFragmentText = new WordFragment();
wordFragmentText.addText("New paragraph.");

// add the WordFragments as inline contents in the same paragraph
docx.addText([wordFragmentBookmark, wordFragmentText]);

docx.save().then(contents => {
    fs.writeFileSync("addLink_2.docx", Buffer.from(contents));
});
