Implement HTML ruby tags for east-asian languages (#30897)

This commit is contained in:
Emelia Smith 2024-07-03 22:05:59 +02:00 committed by GitHub
parent 9be77fc0db
commit 47f0faebc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 1 deletions

View File

@ -65,7 +65,7 @@ class Sanitize
end end
MASTODON_STRICT = freeze_config( MASTODON_STRICT = freeze_config(
elements: %w(p br span a del pre blockquote code b strong u i em ul ol li), elements: %w(p br span a del pre blockquote code b strong u i em ul ol li ruby rt rp),
attributes: { attributes: {
'a' => %w(href rel class translate), 'a' => %w(href rel class translate),

View File

@ -41,6 +41,14 @@ RSpec.describe HtmlAwareFormatter do
expect(subject).to_not include 'status__content__spoiler-link' expect(subject).to_not include 'status__content__spoiler-link'
end end
end end
context 'when given text containing ruby tags for east-asian languages' do
let(:text) { '<ruby>明日 <rp>(</rp><rt>Ashita</rt><rp>)</rp></ruby>' }
it 'keeps the ruby tags' do
expect(subject).to eq '<ruby>明日 <rp>(</rp><rt>Ashita</rt><rp>)</rp></ruby>'
end
end
end end
end end
end end

View File

@ -72,6 +72,14 @@ RSpec.describe PlainTextFormatter do
expect(subject).to eq 'Lorem ipsum' expect(subject).to eq 'Lorem ipsum'
end end
end end
context 'when text contains HTML ruby tags' do
let(:status) { Fabricate(:status, account: remote_account, text: '<p>Lorem <ruby>明日 <rp>(</rp><rt>Ashita</rt><rp>)</rp></ruby> ipsum</p>') }
it 'strips the comment' do
expect(subject).to eq 'Lorem 明日 (Ashita) ipsum'
end
end
end end
end end
end end

View File

@ -18,6 +18,10 @@ describe Sanitize::Config do
expect(Sanitize.fragment('<p>Check out:</p><ol start="3" reversed=""><li>Foo</li><li>Bar</li></ol>', subject)).to eq '<p>Check out:</p><ol start="3" reversed=""><li>Foo</li><li>Bar</li></ol>' expect(Sanitize.fragment('<p>Check out:</p><ol start="3" reversed=""><li>Foo</li><li>Bar</li></ol>', subject)).to eq '<p>Check out:</p><ol start="3" reversed=""><li>Foo</li><li>Bar</li></ol>'
end end
it 'keeps ruby tags' do
expect(Sanitize.fragment('<p><ruby>明日 <rp>(</rp><rt>Ashita</rt><rp>)</rp></ruby></p>', subject)).to eq '<p><ruby>明日 <rp>(</rp><rt>Ashita</rt><rp>)</rp></ruby></p>'
end
it 'removes a without href' do it 'removes a without href' do
expect(Sanitize.fragment('<a>Test</a>', subject)).to eq 'Test' expect(Sanitize.fragment('<a>Test</a>', subject)).to eq 'Test'
end end