Add declarative break()
This commit is contained in:
@ -158,6 +158,15 @@ Sometimes you would want to put text underneath another line of text but inside
|
|||||||
```ts
|
```ts
|
||||||
const text = new TextRun({
|
const text = new TextRun({
|
||||||
text: "break",
|
text: "break",
|
||||||
break: true,
|
break: 1,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Adding two breaks:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const text = new TextRun({
|
||||||
|
text: "break",
|
||||||
|
break: 2,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -239,13 +239,29 @@ describe("Run", () => {
|
|||||||
|
|
||||||
describe("#break()", () => {
|
describe("#break()", () => {
|
||||||
it("it should add break to the run", () => {
|
it("it should add break to the run", () => {
|
||||||
const run = new Run({});
|
const run = new Run({
|
||||||
run.break();
|
break: 1,
|
||||||
|
});
|
||||||
const tree = new Formatter().format(run);
|
const tree = new Formatter().format(run);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [{ "w:br": {} }],
|
"w:r": [{ "w:br": {} }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("it should add two breaks to the run", () => {
|
||||||
|
const run = new Run({
|
||||||
|
break: 2,
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{ "w:br": {} },
|
||||||
|
{
|
||||||
|
"w:br": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#font()", () => {
|
describe("#font()", () => {
|
||||||
|
@ -11,6 +11,7 @@ import { Text } from "./run-components/text";
|
|||||||
|
|
||||||
export interface IRunOptions extends IRunPropertiesOptions {
|
export interface IRunOptions extends IRunPropertiesOptions {
|
||||||
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
||||||
|
readonly break?: number;
|
||||||
readonly text?: string;
|
readonly text?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,10 +63,11 @@ export class Run extends XmlComponent {
|
|||||||
} else if (options.text) {
|
} else if (options.text) {
|
||||||
this.root.push(new Text(options.text));
|
this.root.push(new Text(options.text));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public break(): Run {
|
if (options.break) {
|
||||||
this.root.splice(1, 0, new Break());
|
for (let i = 0; i < options.break; i++) {
|
||||||
return this;
|
this.root.splice(1, 0, new Break());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user