[英]How to format half size with <sup> tag?
下面是一个function,用于拼词。 鉴于第一个或最后一个单词可能是 7 1/2 之类的字符串,我将如何确保这一点; 如果单词包含分数,请使用(上标)标记格式化分数。所以它显示得很好,如下所示?
export const joinWords = (words: string[]): string => {
if (words.length === 1) {
return words[0];
}
const firstWords = words.slice(0, words.length - 1);
const lastWord = words[words.length - 1];
const oxfordComma = words.length > 2;
//if firstWords or lastword contains "/"...Logic???
return firstWords.join(', ') + `${oxfordComma ? ', ' : ''} and ${lastWord}`;
};
我找到了另一种方法,我使用替换方法。 我正在使用 svelte 因此 onmount ..
onMount(() => {
//join the words
const test = joinWords(optionNames);
//replace the "1/2" since I am only using 1/2 for clothing sizes...this may not work for other fractions..
const newTest = test.replace('1/2', '½');
testWord = newTest;
});
//be sure to return as html...again im in svelte.
<span>{@html testWord} </span><br />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.