Skip to content

Commit 15e43ab

Browse files
committed
chore(multitext): add superscript/subscript
1 parent 01071f3 commit 15e43ab

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/helper/modify-text-helper.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ export default class ModifyTextHelper {
8787
if (style.isUnderlined !== undefined) {
8888
ModifyTextHelper.setUnderlined(style.isUnderlined)(element);
8989
}
90+
if (style.isSuperscript !== undefined) {
91+
ModifyTextHelper.setSuperscript(style.isSuperscript)(element);
92+
}
93+
if (style.isSubscript !== undefined) {
94+
ModifyTextHelper.setSubscript(style.isSubscript)(element);
95+
}
9096
};
9197

9298
/**
@@ -137,6 +143,24 @@ export default class ModifyTextHelper {
137143
}
138144
};
139145

146+
/**
147+
* Set superscript attribute on text
148+
*/
149+
static setSuperscript =
150+
(isSuperscript: boolean) =>
151+
(element: XmlElement): void => {
152+
ModifyXmlHelper.attribute('baseline', isSuperscript ? '30000' : '0')(element);
153+
};
154+
155+
/**
156+
* Set subscript attribute on text
157+
*/
158+
static setSubscript =
159+
(isSubscript: boolean) =>
160+
(element: XmlElement): void => {
161+
ModifyXmlHelper.attribute('baseline', isSubscript ? '-25000' : '0')(element);
162+
};
163+
140164
/**
141165
* Set bullet type (font and character) for bullet points
142166
*/

src/types/modify-types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ export type Border = {
4646
weight?: number;
4747
color?: Color;
4848
};
49+
4950
export type TextStyle = {
5051
size?: number;
5152
color?: Color;
5253
isBold?: boolean;
5354
isItalics?: boolean;
5455
isUnderlined?: boolean;
56+
isSuperscript?: boolean;
57+
isSubscript?: boolean;
5558
};
5659

5760
export type ImageStyle = {

0 commit comments

Comments
 (0)