// add a link to a URL with styles in a text

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

const docx = new CreateDocx();

// create a link WordFragment
const wordFragmentLink = new WordFragment();
const link: OptionsLink = {
    link: "https://www.phpdocx.com",
    text: "phpdocx",
};
wordFragmentLink.addLink(link);

// create text WordFragments
const wordFragmentTextA = new WordFragment();
wordFragmentTextA.addText("A link to ");
const wordFragmentTextB = new WordFragment();
wordFragmentTextB.addText(" in the middle of a paragraph.");

// add the WordFragments as inline contents in the same paragraph
docx.addText([wordFragmentTextA, wordFragmentLink, wordFragmentTextB]);

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