:feat: support emphasis mark
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { AlignmentType, IIndentAttributesProperties, ISpacingProperties, UnderlineType } from "../paragraph";
|
||||
import { AlignmentType, EmphasisMarkType, IIndentAttributesProperties, ISpacingProperties, UnderlineType } from "../paragraph";
|
||||
import { ShadingType } from "../table";
|
||||
|
||||
export interface IRunStyleOptions {
|
||||
@ -15,6 +15,9 @@ export interface IRunStyleOptions {
|
||||
readonly type?: UnderlineType;
|
||||
readonly color?: string;
|
||||
};
|
||||
readonly emphasisMark?: {
|
||||
readonly type?: EmphasisMarkType;
|
||||
};
|
||||
readonly color?: string;
|
||||
readonly font?: string;
|
||||
readonly characterSpacing?: number;
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
import { EmphasisMarkType } from "file/paragraph/run/emphasis-mark";
|
||||
import { UnderlineType } from "file/paragraph/run/underline";
|
||||
import { ShadingType } from "file/table";
|
||||
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", () => {
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
@ -616,7 +677,17 @@ describe("CharacterStyle", () => {
|
||||
"w:style": [
|
||||
{ _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": {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { EmphasisMarkType } from "file/paragraph/run/emphasis-mark";
|
||||
import * as formatting from "file/paragraph/run/formatting";
|
||||
import { RunProperties } from "file/paragraph/run/properties";
|
||||
import { UnderlineType } from "file/paragraph/run/underline";
|
||||
@ -23,6 +24,9 @@ export interface IBaseCharacterStyleOptions {
|
||||
readonly type?: UnderlineType;
|
||||
readonly color?: string;
|
||||
};
|
||||
readonly emphasisMark?: {
|
||||
readonly type?: EmphasisMarkType;
|
||||
};
|
||||
readonly color?: string;
|
||||
readonly font?: string;
|
||||
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));
|
||||
}
|
||||
|
||||
if (options.run.emphasisMark) {
|
||||
this.runProperties.push(new formatting.EmphasisMark(options.run.emphasisMark.type));
|
||||
}
|
||||
|
||||
if (options.run.color) {
|
||||
this.runProperties.push(new formatting.Color(options.run.color));
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
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 { ShadingType } from "file/table";
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
@ -49,7 +49,15 @@ describe("ParagraphStyle", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", quickFormat: true });
|
||||
const tree = new Formatter().format(style);
|
||||
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);
|
||||
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);
|
||||
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" } },
|
||||
{
|
||||
"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": [
|
||||
{ _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", () => {
|
||||
const style = new ParagraphStyle({
|
||||
id: "myStyleId",
|
||||
@ -639,7 +722,15 @@ describe("ParagraphStyle", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", link: "MyLink" });
|
||||
const tree = new Formatter().format(style);
|
||||
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 tree = new Formatter().format(style);
|
||||
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 tree = new Formatter().format(style);
|
||||
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));
|
||||
}
|
||||
|
||||
if (options.run.emphasisMark) {
|
||||
this.runProperties.push(new formatting.EmphasisMark(options.run.emphasisMark.type));
|
||||
}
|
||||
|
||||
if (options.run.color) {
|
||||
this.runProperties.push(new formatting.Color(options.run.color));
|
||||
}
|
||||
|
Reference in New Issue
Block a user