Add SymbolRun to allow adding symbols inline
This commit is contained in:
28
src/file/paragraph/run/run-components/symbol.spec.ts
Normal file
28
src/file/paragraph/run/run-components/symbol.spec.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { Symbol } from "./symbol";
|
||||
|
||||
describe("Symbol", () => {
|
||||
describe("#constructor", () => {
|
||||
// Note: if no character is given, the output is a MS Windows logo
|
||||
it("creates an empty symbol run if no character is given", () => {
|
||||
const s = new Symbol();
|
||||
const f = new Formatter().format(s);
|
||||
expect(f).to.deep.equal({ "w:sym": { _attr: { "w:char": "", "w:font": "Wingdings" } } });
|
||||
});
|
||||
|
||||
it("creates the provided symbol with default font", () => {
|
||||
const s = new Symbol("F071");
|
||||
const f = new Formatter().format(s);
|
||||
expect(f).to.deep.equal({ "w:sym": { _attr: { "w:char": "F071", "w:font": "Wingdings" } } });
|
||||
});
|
||||
|
||||
it("creates the provided symbol with the provided font", () => {
|
||||
const s = new Symbol("F071", "Arial");
|
||||
const f = new Formatter().format(s);
|
||||
expect(f).to.deep.equal({ "w:sym": { _attr: { "w:char": "F071", "w:font": "Arial" } } });
|
||||
});
|
||||
});
|
||||
});
|
20
src/file/paragraph/run/run-components/symbol.ts
Normal file
20
src/file/paragraph/run/run-components/symbol.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface ISymbolAttributesProperties {
|
||||
readonly char: string;
|
||||
readonly symbolfont?: string;
|
||||
}
|
||||
|
||||
class SymbolAttributes extends XmlAttributeComponent<ISymbolAttributesProperties> {
|
||||
protected readonly xmlKeys = {
|
||||
char: "w:char",
|
||||
symbolfont: "w:font",
|
||||
};
|
||||
}
|
||||
|
||||
export class Symbol extends XmlComponent {
|
||||
constructor(char: string = "", symbolfont: string = "Wingdings") {
|
||||
super("w:sym");
|
||||
this.root.push(new SymbolAttributes({ char: char, symbolfont: symbolfont }));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user