allow incoming ruby tag

This commit is contained in:
Lhc_fl 2024-10-17 10:54:34 +08:00 committed by laoXong
parent b6da190536
commit a28a61a41d
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(')'));
// 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);
}
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 : '';