Merge pull request #278 from filippomuscolino/feat/style-improvements
Add bold and italics to character style + customize hyperlink
This commit is contained in:
@ -5,6 +5,7 @@ import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink
|
|||||||
|
|
||||||
export class Hyperlink extends XmlComponent {
|
export class Hyperlink extends XmlComponent {
|
||||||
public readonly linkId: number;
|
public readonly linkId: number;
|
||||||
|
private readonly textRun: TextRun;
|
||||||
|
|
||||||
constructor(text: string, relationshipsCount: number, anchor?: string) {
|
constructor(text: string, relationshipsCount: number, anchor?: string) {
|
||||||
super("w:hyperlink");
|
super("w:hyperlink");
|
||||||
@ -19,6 +20,11 @@ export class Hyperlink extends XmlComponent {
|
|||||||
|
|
||||||
const attributes = new HyperlinkAttributes(props);
|
const attributes = new HyperlinkAttributes(props);
|
||||||
this.root.push(attributes);
|
this.root.push(attributes);
|
||||||
this.root.push(new TextRun(text).style("Hyperlink"));
|
this.textRun = new TextRun(text).style("Hyperlink");
|
||||||
|
this.root.push(this.textRun);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get TextRun(): TextRun {
|
||||||
|
return this.textRun;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,6 +243,56 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("#bold", () => {
|
||||||
|
const style = new CharacterStyle("myStyleId").bold();
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
|
{
|
||||||
|
"w:rPr": [{ "w:b": [{ _attr: { "w:val": true } }] }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:uiPriority": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:val": "99",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:unhideWhenUsed": [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("#italics", () => {
|
||||||
|
const style = new CharacterStyle("myStyleId").italics();
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
|
{
|
||||||
|
"w:rPr": [{ "w:i": [{ _attr: { "w:val": true } }] }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:uiPriority": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:val": "99",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:unhideWhenUsed": [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("#link", () => {
|
it("#link", () => {
|
||||||
const style = new CharacterStyle("myStyleId").link("MyLink");
|
const style = new CharacterStyle("myStyleId").link("MyLink");
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
|
@ -29,6 +29,14 @@ export class CharacterStyle extends Style {
|
|||||||
return this.addRunProperty(new formatting.Color(color));
|
return this.addRunProperty(new formatting.Color(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bold(): CharacterStyle {
|
||||||
|
return this.addRunProperty(new formatting.Bold());
|
||||||
|
}
|
||||||
|
|
||||||
|
public italics(): CharacterStyle {
|
||||||
|
return this.addRunProperty(new formatting.Italics());
|
||||||
|
}
|
||||||
|
|
||||||
public underline(underlineType?: string, color?: string): CharacterStyle {
|
public underline(underlineType?: string, color?: string): CharacterStyle {
|
||||||
return this.addRunProperty(new formatting.Underline(underlineType, color));
|
return this.addRunProperty(new formatting.Underline(underlineType, color));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user