handle more complex ruby from/to html - fixes #605

this is not exactly great, but it should be "good enough"

note that the new `group` function should not escape in the wild, as
we don't document it and only use it internally

I tried using `$[scale foo bar]` instead of `$[group foo bar]`, but
that would be rendered as `<i>foo bar</i>` when sent over the network
to non-misskey instances, and we don't want that
This commit is contained in:
dakkar 2025-01-18 12:51:38 +00:00
parent 42d8279610
commit 01a5300be8
3 changed files with 84 additions and 0 deletions

View file

@ -45,6 +45,12 @@ describe('MfmService', () => {
const output = '<p><pre><code>&lt;p&gt;Hello, world!&lt;/p&gt;</code></pre></p>';
assert.equal(mfmService.toHtml(mfm.parse(input)), output);
});
test('ruby', () => {
const input = '$[ruby $[group *some* text] ignore me]';
const output = '<p><ruby><span><i>some</i> text</span><rp>(</rp><rt>ignore me</rt><rp>)</rp></ruby></p>';
assert.equal(mfmService.toHtml(mfm.parse(input)), output);
});
});
describe('fromHtml', () => {
@ -115,5 +121,12 @@ describe('MfmService', () => {
test('hashtag', () => {
assert.deepStrictEqual(mfmService.fromHtml('<p>a <a href="https://example.com/tags/a">#a</a> d</p>', ['#a']), 'a #a d');
});
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]'
);
});
});
});