allow incoming ruby tag

This commit is contained in:
Lhc_fl 2024-10-17 10:54:34 +08:00 committed by fly_mc
parent a201b6e40b
commit f124666e58
2 changed files with 28 additions and 3 deletions

View file

@ -200,6 +200,21 @@ export class MfmService {
break;
}
case 'ruby': {
const rtText = node.childNodes
.filter((n) => n.nodeName === 'rt')
.map((n) => getText(n)).join(' ');
const rubyText = node.childNodes
.filter((n) => treeAdapter.isTextNode(n))
.map((n) => getText(n)).join(' ');
if (rubyText && rtText) {
text += `$[ruby ${rubyText}|${rtText} ]`;
} else {
appendChildren(node.childNodes);
}
break;
}
case 'p':
case 'h2':
case 'h3':
@ -310,8 +325,14 @@ export class MfmService {
const rpEndEl = doc.createElement('rp');
rpEndEl.appendChild(doc.createTextNode(')'));
rubyEl.appendChild(doc.createTextNode(text.split(' ')[0]));
rtEl.appendChild(doc.createTextNode(text.split(' ')[1]));
// Optimization for Latin users
if (text.includes('|')) {
rubyEl.appendChild(doc.createTextNode(text.split('|')[0]));
rtEl.appendChild(doc.createTextNode(text.split('|')[1]));
} else {
rubyEl.appendChild(doc.createTextNode(text.split(' ')[0]));
rtEl.appendChild(doc.createTextNode(text.split(' ')[1]));
}
rubyEl.appendChild(rpStartEl);
rubyEl.appendChild(rtEl);
rubyEl.appendChild(rpEndEl);

View file

@ -289,7 +289,11 @@ export default function (props: MfmProps, { emit }: { emit: SetupContext<MfmEven
if (!disableNyaize && shouldNyaize) {
text = Misskey.nyaize(text);
}
return h('ruby', {}, [text.split(' ')[0], h('rt', text.split(' ')[1])]);
if (text.includes('|')) {
return h('ruby', {}, [text.split('|')[0], h('rt', text.split('|')[1])]);
} else {
return h('ruby', {}, [text.split(' ')[0], h('rt', text.split(' ')[1])]);
}
} else {
const rt = token.children.at(-1)!;
let text = rt.type === 'text' ? rt.props.text : '';