Add language support
This commit is contained in:
29
src/file/paragraph/run/language.spec.ts
Normal file
29
src/file/paragraph/run/language.spec.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { createLanguageComponent } from "./language";
|
||||
|
||||
describe("Language", () => {
|
||||
describe("#createLanguageComponent", () => {
|
||||
it("should create a language component", () => {
|
||||
const tree = new Formatter().format(
|
||||
createLanguageComponent({
|
||||
value: "en-US",
|
||||
eastAsia: "zh-CN",
|
||||
bidirectional: "ar-SA",
|
||||
}),
|
||||
);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:lang": {
|
||||
_attr: {
|
||||
"w:bidi": "ar-SA",
|
||||
"w:eastAsia": "zh-CN",
|
||||
"w:val": "en-US",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
35
src/file/paragraph/run/language.ts
Normal file
35
src/file/paragraph/run/language.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
// <xsd:complexType name="CT_Language">
|
||||
// <xsd:attribute name="val" type="s:ST_Lang" use="optional"/>
|
||||
// <xsd:attribute name="eastAsia" type="s:ST_Lang" use="optional"/>
|
||||
// <xsd:attribute name="bidi" type="s:ST_Lang" use="optional"/>
|
||||
// </xsd:complexType>
|
||||
export interface ILanguageOptions {
|
||||
readonly value?: string;
|
||||
readonly eastAsia?: string;
|
||||
readonly bidirectional?: string;
|
||||
}
|
||||
|
||||
export const createLanguageComponent = (options: ILanguageOptions): XmlComponent =>
|
||||
new BuilderElement<{
|
||||
readonly value?: string;
|
||||
readonly eastAsia?: string;
|
||||
readonly bidirectional?: string;
|
||||
}>({
|
||||
name: "w:lang",
|
||||
attributes: {
|
||||
value: {
|
||||
key: "w:val",
|
||||
value: options.value,
|
||||
},
|
||||
eastAsia: {
|
||||
key: "w:eastAsia",
|
||||
value: options.eastAsia,
|
||||
},
|
||||
bidirectional: {
|
||||
key: "w:bidi",
|
||||
value: options.bidirectional,
|
||||
},
|
||||
},
|
||||
});
|
@ -2,7 +2,6 @@ import { BorderElement, IBorderOptions } from "@file/border";
|
||||
import { IShadingAttributesProperties, Shading } from "@file/shading";
|
||||
import { ChangeAttributes, IChangedAttributesProperties } from "@file/track-revision/track-revision";
|
||||
import {
|
||||
BuilderElement,
|
||||
HpsMeasureElement,
|
||||
IgnoreIfEmptyXmlComponent,
|
||||
NumberValueElement,
|
||||
@ -13,6 +12,7 @@ import {
|
||||
|
||||
import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark";
|
||||
import { CharacterSpacing, Color, Highlight, HighlightComplexScript } from "./formatting";
|
||||
import { createLanguageComponent, ILanguageOptions } from "./language";
|
||||
import { IFontAttributesProperties, RunFonts } from "./run-fonts";
|
||||
import { SubScript, SuperScript } from "./script";
|
||||
import { Underline, UnderlineType } from "./underline";
|
||||
@ -52,16 +52,7 @@ export interface IRunStylePropertiesOptions {
|
||||
readonly emboss?: boolean;
|
||||
readonly imprint?: boolean;
|
||||
readonly revision?: IRunPropertiesChangeOptions;
|
||||
// <xsd:complexType name="CT_Language">
|
||||
// <xsd:attribute name="val" type="s:ST_Lang" use="optional"/>
|
||||
// <xsd:attribute name="eastAsia" type="s:ST_Lang" use="optional"/>
|
||||
// <xsd:attribute name="bidi" type="s:ST_Lang" use="optional"/>
|
||||
// </xsd:complexType>
|
||||
readonly language?: {
|
||||
readonly value?: string;
|
||||
readonly eastAsia?: string;
|
||||
readonly bidirectional?: string;
|
||||
};
|
||||
readonly language?: ILanguageOptions;
|
||||
readonly border?: IBorderOptions;
|
||||
readonly vanish?: boolean;
|
||||
readonly specVanish?: boolean;
|
||||
@ -253,29 +244,7 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
||||
}
|
||||
|
||||
if (options.language) {
|
||||
this.push(
|
||||
new BuilderElement<{
|
||||
readonly value: string;
|
||||
readonly eastAsia: string;
|
||||
readonly bidirectional: string;
|
||||
}>({
|
||||
name: "w:lang",
|
||||
attributes: {
|
||||
value: {
|
||||
key: "w:val",
|
||||
value: options.language.value,
|
||||
},
|
||||
eastAsia: {
|
||||
key: "w:eastAsia",
|
||||
value: options.language.eastAsia,
|
||||
},
|
||||
bidirectional: {
|
||||
key: "w:bidi",
|
||||
value: options.language.bidirectional,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
this.push(createLanguageComponent(options.language));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user