mirror of
https://github.com/misskey-dev/misskey.git
synced 2025-01-10 00:49:22 +09:00
Compare commits
2 Commits
60f8ff6515
...
0d0d75b4d6
Author | SHA1 | Date | |
---|---|---|---|
|
0d0d75b4d6 | ||
|
a74cc1401d |
@ -172,35 +172,33 @@ export class MfmService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'ruby': {
|
case 'ruby': {
|
||||||
const ruby: [string, string][] = [];
|
let ruby: [string, string][] = [];
|
||||||
for (const child of node.childNodes) {
|
for (const child of node.childNodes) {
|
||||||
if (child.nodeName === 'rp') {
|
if (child.nodeName === 'rp') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (treeAdapter.isTextNode(child) && !child.value.match(/\s|\[|\]/)) {
|
if (treeAdapter.isTextNode(child) && !/\s|\[|\]/.test(child.value)) {
|
||||||
ruby.push([child.value, '']);
|
ruby.push([child.value, '']);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (child.nodeName === 'rt' && ruby.length > 0) {
|
if (child.nodeName === 'rt' && ruby.length > 0) {
|
||||||
const rt = getText(child);
|
const rt = getText(child);
|
||||||
if (rt.match(/\s|\[|\]/)) {
|
if (/\s|\[|\]/.test(rt)) {
|
||||||
// If any space is included in rt, it is treated as a normal text
|
// If any space is included in rt, it is treated as a normal text
|
||||||
|
ruby = [];
|
||||||
|
appendChildren(node.childNodes);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
ruby[ruby.length - 1][1] = rt;
|
ruby.at(-1)![1] = rt;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If any other element is included in ruby, it is treated as a normal text
|
// If any other element is included in ruby, it is treated as a normal text
|
||||||
|
ruby = [];
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (const [base, rt] of ruby) {
|
for (const [base, rt] of ruby) {
|
||||||
if (rt.trim() === "") {
|
|
||||||
// If any space is included in rt, it is treated as a normal text
|
|
||||||
appendChildren(node.childNodes);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
text += `$[ruby ${base} ${rt}]`;
|
text += `$[ruby ${base} ${rt}]`;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -111,16 +111,20 @@ describe('MfmService', () => {
|
|||||||
test('ruby', () => {
|
test('ruby', () => {
|
||||||
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Misskey<rp>(</rp><rt>ミスキー</rt><rp>)</rp></ruby> b</p>'), 'a $[ruby Misskey ミスキー] b');
|
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Misskey<rp>(</rp><rt>ミスキー</rt><rp>)</rp></ruby> b</p>'), 'a $[ruby Misskey ミスキー] b');
|
||||||
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Misskey<rp>(</rp><rt>ミスキー</rt><rp>)</rp>Misskey<rp>(</rp><rt>ミスキー</rt><rp>)</rp></ruby> b</p>'), 'a $[ruby Misskey ミスキー]$[ruby Misskey ミスキー] b');
|
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Misskey<rp>(</rp><rt>ミスキー</rt><rp>)</rp>Misskey<rp>(</rp><rt>ミスキー</rt><rp>)</rp></ruby> b</p>'), 'a $[ruby Misskey ミスキー]$[ruby Misskey ミスキー] b');
|
||||||
})
|
});
|
||||||
|
|
||||||
test('ruby with spaces', () => {
|
test('ruby with spaces', () => {
|
||||||
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Miss key<rp>(</rp><rt>ミスキー</rt><rp>)</rp> b</ruby> c</p>'), 'a Miss key(ミスキー) b c');
|
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Miss key<rp>(</rp><rt>ミスキー</rt><rp>)</rp> b</ruby> c</p>'), 'a Miss key(ミスキー) b c');
|
||||||
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Misskey<rp>(</rp><rt>ミス キー</rt><rp>)</rp> b</ruby> c</p>'), 'a Misskey(ミス キー) b c');
|
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Misskey<rp>(</rp><rt>ミス キー</rt><rp>)</rp> b</ruby> c</p>'), 'a Misskey(ミス キー) b c');
|
||||||
})
|
assert.deepStrictEqual(
|
||||||
|
mfmService.fromHtml('<p>a <ruby>Misskey<rp>(</rp><rt>ミスキー</rt><rp>)</rp>Misskey<rp>(</rp><rt>ミス キー</rt><rp>)</rp>Misskey<rp>(</rp><rt>ミスキー</rt><rp>)</rp></ruby> b</p>'),
|
||||||
|
'a Misskey(ミスキー)Misskey(ミス キー)Misskey(ミスキー) b'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('ruby with other inline tags', () => {
|
test('ruby with other inline tags', () => {
|
||||||
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby><strong>Misskey</strong><rp>(</rp><rt>ミスキー</rt><rp>)</rp> b</ruby> c</p>'), 'a **Misskey**(ミスキー) b c');
|
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby><strong>Misskey</strong><rp>(</rp><rt>ミスキー</rt><rp>)</rp> b</ruby> c</p>'), 'a **Misskey**(ミスキー) b c');
|
||||||
})
|
});
|
||||||
|
|
||||||
test('mention', () => {
|
test('mention', () => {
|
||||||
assert.deepStrictEqual(mfmService.fromHtml('<p>a <a href="https://example.com/@user" class="u-url mention">@user</a> d</p>'), 'a @user@example.com d');
|
assert.deepStrictEqual(mfmService.fromHtml('<p>a <a href="https://example.com/@user" class="u-url mention">@user</a> d</p>'), 'a @user@example.com d');
|
||||||
|
Loading…
Reference in New Issue
Block a user