fix our ruby/group hack
This commit is contained in:
parent
29b1f61d67
commit
d426e2a7ef
2 changed files with 18 additions and 9 deletions
|
@ -179,7 +179,8 @@ export class MfmService {
|
|||
break;
|
||||
}
|
||||
|
||||
case 'ruby': {
|
||||
// this is here only to catch upstream changes!
|
||||
case 'ruby--': {
|
||||
let ruby: [string, string][] = [];
|
||||
for (const child of node.childNodes) {
|
||||
if (child.nodeName === 'rp') {
|
||||
|
@ -310,16 +311,24 @@ export class MfmService {
|
|||
continue;
|
||||
}
|
||||
if (child.nodeName === 'rt') {
|
||||
text += '$[ruby $[group ';
|
||||
// the only case in which we don't need a `$[group ]`
|
||||
// is when both sides of the ruby are simple words
|
||||
const needsGroup = nonRtNodes.length > 1 ||
|
||||
/\s|\[|\]/.test(getText(nonRtNodes[0])) ||
|
||||
/\s|\[|\]/.test(getText(child)) ;
|
||||
text += '$[ruby ';
|
||||
if (needsGroup) text += '$[group ';
|
||||
appendChildren(nonRtNodes);
|
||||
text += '] ';
|
||||
if (needsGroup) text += ']';
|
||||
text += ' ';
|
||||
analyze(child);
|
||||
text += '] ';
|
||||
text += ']';
|
||||
nonRtNodes = [];
|
||||
continue;
|
||||
}
|
||||
nonRtNodes.push(child);
|
||||
}
|
||||
appendChildren(nonRtNodes);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -158,16 +158,16 @@ describe('MfmService', () => {
|
|||
});
|
||||
|
||||
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>Misskey<rp>(</rp><rt>ミス キー</rt><rp>)</rp> b</ruby> c</p>'), 'a Misskey(ミス キー) b c');
|
||||
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Miss key<rp>(</rp><rt>ミスキー</rt><rp>)</rp> b</ruby> c</p>'), 'a $[ruby $[group Miss key] ミスキー] b c');
|
||||
assert.deepStrictEqual(mfmService.fromHtml('<p>a <ruby>Misskey<rp>(</rp><rt>ミス キー</rt><rp>)</rp> b</ruby> c</p>'), 'a $[ruby $[group 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'
|
||||
'a $[ruby Misskey ミスキー]$[ruby $[group Misskey] ミス キー]$[ruby Misskey ミスキー] b'
|
||||
);
|
||||
});
|
||||
|
||||
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 $[ruby **Misskey** ミスキー] b c');
|
||||
});
|
||||
|
||||
test('mention', () => {
|
||||
|
@ -181,7 +181,7 @@ describe('MfmService', () => {
|
|||
test('ruby', () => {
|
||||
assert.deepStrictEqual(
|
||||
mfmService.fromHtml('<ruby> <i>some</i> text <rp>(</rp><rt>ignore me</rt><rp>)</rp> and <rt>more</rt></ruby>'),
|
||||
'$[ruby $[group <i>some</i> text ] ignore me] $[ruby $[group and ] more]'
|
||||
'$[ruby $[group <i>some</i> text ] ignore me]$[ruby $[group and ] more]'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue