Merge pull request #546 from wangfengming/feature/emphasis-mark
Feature/emphasis mark
This commit is contained in:
@ -161,6 +161,10 @@ doc.addSection({
|
|||||||
text: "and then underlined ",
|
text: "and then underlined ",
|
||||||
underline: {},
|
underline: {},
|
||||||
}),
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "and then emphasis-mark ",
|
||||||
|
emphasisMark: {},
|
||||||
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "and back to normal.",
|
text: "and back to normal.",
|
||||||
}),
|
}),
|
||||||
|
@ -22,7 +22,8 @@ const name = new TextRun({
|
|||||||
### Run formatting
|
### Run formatting
|
||||||
|
|
||||||
- `bold`, `italics`, `smallCaps`, `allCaps`, `strike`, `doubleStrike`, `subScript`, `superScript`: Set the formatting property to true
|
- `bold`, `italics`, `smallCaps`, `allCaps`, `strike`, `doubleStrike`, `subScript`, `superScript`: Set the formatting property to true
|
||||||
- `underline(style="single", color=null)`: Set the underline style and color
|
- `underline({type="single", color=null})`: Set the underline style and color
|
||||||
|
- `emphasisMark({type="dot"})`: Set the emphasis mark style
|
||||||
- `color(color)`: Set the text color, using 6 hex characters for RRGGBB (no leading `#`)
|
- `color(color)`: Set the text color, using 6 hex characters for RRGGBB (no leading `#`)
|
||||||
- `size(halfPts)`: Set the font size, measured in half-points
|
- `size(halfPts)`: Set the font size, measured in half-points
|
||||||
- `font(name)`: Set the run's font
|
- `font(name)`: Set the run's font
|
||||||
|
@ -68,6 +68,15 @@ const text = new TextRun({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Emphasis Mark
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const text = new TextRun({
|
||||||
|
text: "and then emphasis mark",
|
||||||
|
emphasisMark: {},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
### Strike through
|
### Strike through
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "5.0.2",
|
"version": "5.1.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -3,7 +3,7 @@ import { expect } from "chai";
|
|||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import { EMPTY_OBJECT } from "file/xml-components";
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
import { AlignmentType, TabStopPosition } from "../paragraph";
|
import { AlignmentType, EmphasisMarkType, TabStopPosition } from "../paragraph";
|
||||||
import { UnderlineType } from "../paragraph/run/underline";
|
import { UnderlineType } from "../paragraph/run/underline";
|
||||||
import { ShadingType } from "../table";
|
import { ShadingType } from "../table";
|
||||||
import { AbstractNumbering } from "./abstract-numbering";
|
import { AbstractNumbering } from "./abstract-numbering";
|
||||||
@ -433,7 +433,16 @@ describe("AbstractNumbering", () => {
|
|||||||
const tree = new Formatter().format(abstractNumbering);
|
const tree = new Formatter().format(abstractNumbering);
|
||||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
|
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{ "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } },
|
{
|
||||||
|
"w:rFonts": {
|
||||||
|
_attr: {
|
||||||
|
"w:ascii": "Times",
|
||||||
|
"w:cs": "Times",
|
||||||
|
"w:eastAsia": "Times",
|
||||||
|
"w:hAnsi": "Times",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -582,6 +591,48 @@ describe("AbstractNumbering", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#emphasisMark", () => {
|
||||||
|
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
||||||
|
const abstractNumbering = new AbstractNumbering(1, [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: "lowerRoman",
|
||||||
|
text: "%0.",
|
||||||
|
style: {
|
||||||
|
run: {
|
||||||
|
emphasisMark: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
const tree = new Formatter().format(abstractNumbering);
|
||||||
|
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
|
||||||
|
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set the style if given", () => {
|
||||||
|
const abstractNumbering = new AbstractNumbering(1, [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: "lowerRoman",
|
||||||
|
text: "%0.",
|
||||||
|
style: {
|
||||||
|
run: {
|
||||||
|
emphasisMark: {
|
||||||
|
type: EmphasisMarkType.DOT,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
const tree = new Formatter().format(abstractNumbering);
|
||||||
|
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
|
||||||
|
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("#color", () => {
|
it("#color", () => {
|
||||||
const abstractNumbering = new AbstractNumbering(1, [
|
const abstractNumbering = new AbstractNumbering(1, [
|
||||||
{
|
{
|
||||||
|
@ -177,6 +177,10 @@ export class LevelBase extends XmlComponent {
|
|||||||
this.runProperties.push(new formatting.Underline(style.run.underline.type, style.run.underline.color));
|
this.runProperties.push(new formatting.Underline(style.run.underline.type, style.run.underline.color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (style.run.emphasisMark) {
|
||||||
|
this.runProperties.push(new formatting.EmphasisMark(style.run.emphasisMark.type));
|
||||||
|
}
|
||||||
|
|
||||||
if (style.run.color) {
|
if (style.run.color) {
|
||||||
this.runProperties.push(new formatting.Color(style.run.color));
|
this.runProperties.push(new formatting.Color(style.run.color));
|
||||||
}
|
}
|
||||||
|
29
src/file/paragraph/run/emphasis-mark.spec.ts
Normal file
29
src/file/paragraph/run/emphasis-mark.spec.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
|
import * as em from "./emphasis-mark";
|
||||||
|
|
||||||
|
describe("EmphasisMark", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a new EmphasisMark object with w:em as the rootKey", () => {
|
||||||
|
const emphasisMark = new em.EmphasisMark();
|
||||||
|
const tree = new Formatter().format(emphasisMark);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:em": { _attr: { "w:val": "dot" } },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("DotEmphasisMark", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should put value in attribute", () => {
|
||||||
|
const emphasisMark = new em.DotEmphasisMark();
|
||||||
|
const tree = new Formatter().format(emphasisMark);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:em": { _attr: { "w:val": "dot" } },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
28
src/file/paragraph/run/emphasis-mark.ts
Normal file
28
src/file/paragraph/run/emphasis-mark.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { Attributes, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
export enum EmphasisMarkType {
|
||||||
|
DOT = "dot",
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class BaseEmphasisMark extends XmlComponent {
|
||||||
|
protected constructor(emphasisMarkType: EmphasisMarkType) {
|
||||||
|
super("w:em");
|
||||||
|
this.root.push(
|
||||||
|
new Attributes({
|
||||||
|
val: emphasisMarkType,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class EmphasisMark extends BaseEmphasisMark {
|
||||||
|
constructor(emphasisMarkType: EmphasisMarkType = EmphasisMarkType.DOT) {
|
||||||
|
super(emphasisMarkType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DotEmphasisMark extends BaseEmphasisMark {
|
||||||
|
constructor() {
|
||||||
|
super(EmphasisMarkType.DOT);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
import { Attributes, XmlComponent } from "file/xml-components";
|
import { Attributes, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
export { Underline } from "./underline";
|
export { Underline } from "./underline";
|
||||||
|
export { EmphasisMark } from "./emphasis-mark";
|
||||||
export { SubScript, SuperScript } from "./script";
|
export { SubScript, SuperScript } from "./script";
|
||||||
export { RunFonts } from "./run-fonts";
|
export { RunFonts } from "./run-fonts";
|
||||||
|
|
||||||
|
@ -5,4 +5,5 @@ export * from "./picture-run";
|
|||||||
export * from "./run-fonts";
|
export * from "./run-fonts";
|
||||||
export * from "./sequential-identifier";
|
export * from "./sequential-identifier";
|
||||||
export * from "./underline";
|
export * from "./underline";
|
||||||
|
export * from "./emphasis-mark";
|
||||||
export * from "./tab";
|
export * from "./tab";
|
||||||
|
@ -5,6 +5,7 @@ import { Formatter } from "export/formatter";
|
|||||||
import { ShadingType } from "file/table";
|
import { ShadingType } from "file/table";
|
||||||
|
|
||||||
import { Run } from "./";
|
import { Run } from "./";
|
||||||
|
import { EmphasisMarkType } from "./emphasis-mark";
|
||||||
import { PageNumber } from "./run";
|
import { PageNumber } from "./run";
|
||||||
import { UnderlineType } from "./underline";
|
import { UnderlineType } from "./underline";
|
||||||
|
|
||||||
@ -84,6 +85,30 @@ describe("Run", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#emphasisMark()", () => {
|
||||||
|
it("should default to 'dot'", () => {
|
||||||
|
const run = new Run({
|
||||||
|
emphasisMark: {},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [{ "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }] }],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set the style type if given", () => {
|
||||||
|
const run = new Run({
|
||||||
|
emphasisMark: {
|
||||||
|
type: EmphasisMarkType.DOT,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [{ "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }] }],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("#smallCaps()", () => {
|
describe("#smallCaps()", () => {
|
||||||
it("it should add smallCaps to the properties", () => {
|
it("it should add smallCaps to the properties", () => {
|
||||||
const run = new Run({
|
const run = new Run({
|
||||||
@ -235,7 +260,16 @@ describe("Run", () => {
|
|||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
{
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{ "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } },
|
{
|
||||||
|
"w:rFonts": {
|
||||||
|
_attr: {
|
||||||
|
"w:ascii": "Times",
|
||||||
|
"w:cs": "Times",
|
||||||
|
"w:eastAsia": "Times",
|
||||||
|
"w:hAnsi": "Times",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -6,6 +6,7 @@ import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run"
|
|||||||
import { FieldInstruction } from "file/table-of-contents/field-instruction";
|
import { FieldInstruction } from "file/table-of-contents/field-instruction";
|
||||||
import { Break } from "./break";
|
import { Break } from "./break";
|
||||||
import { Caps, SmallCaps } from "./caps";
|
import { Caps, SmallCaps } from "./caps";
|
||||||
|
import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark";
|
||||||
import { Begin, End, Separate } from "./field";
|
import { Begin, End, Separate } from "./field";
|
||||||
import {
|
import {
|
||||||
Bold,
|
Bold,
|
||||||
@ -38,6 +39,9 @@ export interface IRunOptions {
|
|||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
readonly type?: UnderlineType;
|
readonly type?: UnderlineType;
|
||||||
};
|
};
|
||||||
|
readonly emphasisMark?: {
|
||||||
|
readonly type?: EmphasisMarkType;
|
||||||
|
};
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
readonly size?: number;
|
readonly size?: number;
|
||||||
readonly rightToLeft?: boolean;
|
readonly rightToLeft?: boolean;
|
||||||
@ -90,6 +94,10 @@ export class Run extends XmlComponent {
|
|||||||
this.properties.push(new Underline(options.underline.type, options.underline.color));
|
this.properties.push(new Underline(options.underline.type, options.underline.color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.emphasisMark) {
|
||||||
|
this.properties.push(new EmphasisMark(options.emphasisMark.type));
|
||||||
|
}
|
||||||
|
|
||||||
if (options.color) {
|
if (options.color) {
|
||||||
this.properties.push(new Color(options.color));
|
this.properties.push(new Color(options.color));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { EmphasisMarkType } from "./emphasis-mark";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { UnderlineType } from "./underline";
|
import { UnderlineType } from "./underline";
|
||||||
@ -44,6 +46,9 @@ describe("SymbolRun", () => {
|
|||||||
color: "red",
|
color: "red",
|
||||||
type: UnderlineType.DOUBLE,
|
type: UnderlineType.DOUBLE,
|
||||||
},
|
},
|
||||||
|
emphasisMark: {
|
||||||
|
type: EmphasisMarkType.DOT,
|
||||||
|
},
|
||||||
color: "green",
|
color: "green",
|
||||||
size: 40,
|
size: 40,
|
||||||
highlight: "yellow",
|
highlight: "yellow",
|
||||||
@ -59,6 +64,7 @@ describe("SymbolRun", () => {
|
|||||||
{ "w:i": { _attr: { "w:val": true } } },
|
{ "w:i": { _attr: { "w:val": true } } },
|
||||||
{ "w:iCs": { _attr: { "w:val": true } } },
|
{ "w:iCs": { _attr: { "w:val": true } } },
|
||||||
{ "w:u": { _attr: { "w:val": "double", "w:color": "red" } } },
|
{ "w:u": { _attr: { "w:val": "double", "w:color": "red" } } },
|
||||||
|
{ "w:em": { _attr: { "w:val": "dot" } } },
|
||||||
{ "w:color": { _attr: { "w:val": "green" } } },
|
{ "w:color": { _attr: { "w:val": "green" } } },
|
||||||
{ "w:sz": { _attr: { "w:val": 40 } } },
|
{ "w:sz": { _attr: { "w:val": 40 } } },
|
||||||
{ "w:szCs": { _attr: { "w:val": 40 } } },
|
{ "w:szCs": { _attr: { "w:val": 40 } } },
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { AlignmentType, IIndentAttributesProperties, ISpacingProperties, UnderlineType } from "../paragraph";
|
import { AlignmentType, EmphasisMarkType, IIndentAttributesProperties, ISpacingProperties, UnderlineType } from "../paragraph";
|
||||||
import { ShadingType } from "../table";
|
import { ShadingType } from "../table";
|
||||||
|
|
||||||
export interface IRunStyleOptions {
|
export interface IRunStyleOptions {
|
||||||
@ -15,6 +15,9 @@ export interface IRunStyleOptions {
|
|||||||
readonly type?: UnderlineType;
|
readonly type?: UnderlineType;
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
};
|
};
|
||||||
|
readonly emphasisMark?: {
|
||||||
|
readonly type?: EmphasisMarkType;
|
||||||
|
};
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
readonly font?: string;
|
readonly font?: string;
|
||||||
readonly characterSpacing?: number;
|
readonly characterSpacing?: number;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
|
import { EmphasisMarkType } from "file/paragraph/run/emphasis-mark";
|
||||||
import { UnderlineType } from "file/paragraph/run/underline";
|
import { UnderlineType } from "file/paragraph/run/underline";
|
||||||
import { ShadingType } from "file/table";
|
import { ShadingType } from "file/table";
|
||||||
import { EMPTY_OBJECT } from "file/xml-components";
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
@ -412,6 +413,66 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#emphasisMark", () => {
|
||||||
|
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
||||||
|
const style = new CharacterStyle({
|
||||||
|
id: "myStyleId",
|
||||||
|
run: {
|
||||||
|
emphasisMark: {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
|
{
|
||||||
|
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:uiPriority": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 99,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set the style if given", () => {
|
||||||
|
const style = new CharacterStyle({
|
||||||
|
id: "myStyleId",
|
||||||
|
run: {
|
||||||
|
emphasisMark: {
|
||||||
|
type: EmphasisMarkType.DOT,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
|
{
|
||||||
|
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:uiPriority": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 99,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("#superScript", () => {
|
it("#superScript", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new CharacterStyle({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
@ -616,7 +677,17 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:shd": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "pct10",
|
||||||
|
"w:fill": "00FFFF",
|
||||||
|
"w:color": "FF0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:uiPriority": {
|
"w:uiPriority": {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { EmphasisMarkType } from "file/paragraph/run/emphasis-mark";
|
||||||
import * as formatting from "file/paragraph/run/formatting";
|
import * as formatting from "file/paragraph/run/formatting";
|
||||||
import { RunProperties } from "file/paragraph/run/properties";
|
import { RunProperties } from "file/paragraph/run/properties";
|
||||||
import { UnderlineType } from "file/paragraph/run/underline";
|
import { UnderlineType } from "file/paragraph/run/underline";
|
||||||
@ -23,6 +24,9 @@ export interface IBaseCharacterStyleOptions {
|
|||||||
readonly type?: UnderlineType;
|
readonly type?: UnderlineType;
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
};
|
};
|
||||||
|
readonly emphasisMark?: {
|
||||||
|
readonly type?: EmphasisMarkType;
|
||||||
|
};
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
readonly font?: string;
|
readonly font?: string;
|
||||||
readonly characterSpacing?: number;
|
readonly characterSpacing?: number;
|
||||||
@ -104,6 +108,10 @@ export class CharacterStyle extends Style {
|
|||||||
this.runProperties.push(new formatting.Underline(options.run.underline.type, options.run.underline.color));
|
this.runProperties.push(new formatting.Underline(options.run.underline.type, options.run.underline.color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.run.emphasisMark) {
|
||||||
|
this.runProperties.push(new formatting.EmphasisMark(options.run.emphasisMark.type));
|
||||||
|
}
|
||||||
|
|
||||||
if (options.run.color) {
|
if (options.run.color) {
|
||||||
this.runProperties.push(new formatting.Color(options.run.color));
|
this.runProperties.push(new formatting.Color(options.run.color));
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import { AlignmentType, TabStopPosition } from "file/paragraph";
|
import { AlignmentType, EmphasisMarkType, TabStopPosition } from "file/paragraph";
|
||||||
import { UnderlineType } from "file/paragraph/run/underline";
|
import { UnderlineType } from "file/paragraph/run/underline";
|
||||||
import { ShadingType } from "file/table";
|
import { ShadingType } from "file/table";
|
||||||
import { EMPTY_OBJECT } from "file/xml-components";
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
@ -49,7 +49,15 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle({ id: "myStyleId", quickFormat: true });
|
const style = new ParagraphStyle({ id: "myStyleId", quickFormat: true });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:qFormat": EMPTY_OBJECT }],
|
"w:style": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:type": "paragraph",
|
||||||
|
"w:styleId": "myStyleId",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -299,7 +307,15 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepLines": EMPTY_OBJECT }] }],
|
"w:style": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:type": "paragraph",
|
||||||
|
"w:styleId": "myStyleId",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ "w:pPr": [{ "w:keepLines": EMPTY_OBJECT }] },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -312,7 +328,15 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepNext": EMPTY_OBJECT }] }],
|
"w:style": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:type": "paragraph",
|
||||||
|
"w:styleId": "myStyleId",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ "w:pPr": [{ "w:keepNext": EMPTY_OBJECT }] },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -473,7 +497,16 @@ describe("ParagraphStyle", () => {
|
|||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{ "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } },
|
{
|
||||||
|
"w:rFonts": {
|
||||||
|
_attr: {
|
||||||
|
"w:ascii": "Times",
|
||||||
|
"w:cs": "Times",
|
||||||
|
"w:eastAsia": "Times",
|
||||||
|
"w:hAnsi": "Times",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -550,7 +583,17 @@ describe("ParagraphStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:shd": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "pct10",
|
||||||
|
"w:fill": "00FFFF",
|
||||||
|
"w:color": "FF0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -617,6 +660,46 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#emphasisMark", () => {
|
||||||
|
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
||||||
|
const style = new ParagraphStyle({
|
||||||
|
id: "myStyleId",
|
||||||
|
run: {
|
||||||
|
emphasisMark: {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
|
{
|
||||||
|
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set the style if given", () => {
|
||||||
|
const style = new ParagraphStyle({
|
||||||
|
id: "myStyleId",
|
||||||
|
run: {
|
||||||
|
emphasisMark: {
|
||||||
|
type: EmphasisMarkType.DOT,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
|
{
|
||||||
|
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("#color", () => {
|
it("#color", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new ParagraphStyle({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
@ -639,7 +722,15 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle({ id: "myStyleId", link: "MyLink" });
|
const style = new ParagraphStyle({ id: "myStyleId", link: "MyLink" });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:link": { _attr: { "w:val": "MyLink" } } }],
|
"w:style": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:type": "paragraph",
|
||||||
|
"w:styleId": "myStyleId",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ "w:link": { _attr: { "w:val": "MyLink" } } },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -647,7 +738,15 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle({ id: "myStyleId", semiHidden: true });
|
const style = new ParagraphStyle({ id: "myStyleId", semiHidden: true });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:semiHidden": EMPTY_OBJECT }],
|
"w:style": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:type": "paragraph",
|
||||||
|
"w:styleId": "myStyleId",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ "w:semiHidden": EMPTY_OBJECT },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -672,7 +771,15 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle({ id: "myStyleId", unhideWhenUsed: true });
|
const style = new ParagraphStyle({ id: "myStyleId", unhideWhenUsed: true });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:unhideWhenUsed": EMPTY_OBJECT }],
|
"w:style": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:type": "paragraph",
|
||||||
|
"w:styleId": "myStyleId",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ "w:unhideWhenUsed": EMPTY_OBJECT },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -114,6 +114,10 @@ export class ParagraphStyle extends Style {
|
|||||||
this.runProperties.push(new formatting.Underline(options.run.underline.type, options.run.underline.color));
|
this.runProperties.push(new formatting.Underline(options.run.underline.type, options.run.underline.color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.run.emphasisMark) {
|
||||||
|
this.runProperties.push(new formatting.EmphasisMark(options.run.emphasisMark.type));
|
||||||
|
}
|
||||||
|
|
||||||
if (options.run.color) {
|
if (options.run.color) {
|
||||||
this.runProperties.push(new formatting.Color(options.run.color));
|
this.runProperties.push(new formatting.Color(options.run.color));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user