mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
* Add target="_blank" (on embeds only!)
* When pasting a link, the cursor position is moved after the paste
* Can't reproduce a link slipping into the embed in front of it
@Tirokk it is an unpleasant side efffect that mentions + hastags appear
differently on Edit+View. That's because they don't get parsed from
HTML, it's a one way, they are write only. So, when viewing content,
hashtags and mentions appear as plain links. I don't think I can do
anything about it.
Regarding some links not being embedded: Only those links that have an
oembed provider in this file:
f44d0f1f96/backend/src/schema/resolvers/embeds/providers.json
...will be embedded. Your example `http://backreaction.blogspot.com` and `https://de.wikipedia.org/wiki/Yin_und_Yang`
have no embed provider and won't be embedded.
We would have to add oembed providers to this list if we wanted to embed those
links, too.
94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
import defaultExtensions from './defaultExtensions.js'
|
|
import { Editor } from 'tiptap'
|
|
|
|
let content
|
|
let createEditor
|
|
|
|
describe('defaultExtensions', () => {
|
|
describe('editor', () => {
|
|
createEditor = () => {
|
|
const componentStub = {
|
|
placeholder: 'placeholder',
|
|
$t: jest.fn(),
|
|
$apollo: {
|
|
mutate: jest.fn(),
|
|
},
|
|
}
|
|
return new Editor({
|
|
content,
|
|
extensions: [...defaultExtensions(componentStub)],
|
|
})
|
|
}
|
|
})
|
|
|
|
it('renders', () => {
|
|
content = ''
|
|
expect(createEditor().getHTML()).toEqual('<p></p>')
|
|
})
|
|
|
|
describe('`content` contains a mentioning', () => {
|
|
beforeEach(() => {
|
|
content =
|
|
'<p>This is a post content mentioning <a class="mention" data-mention-id="alicias-id" href="/profile/f0628376-e692-4167-bdb4-d521de5a014f" target="_blank">@alicia-luettgen</a>.</p>'
|
|
})
|
|
|
|
it('renders mentioning as link', () => {
|
|
const editor = createEditor()
|
|
const expected =
|
|
'<p>This is a post content mentioning <a href="/profile/f0628376-e692-4167-bdb4-d521de5a014f" rel="noopener noreferrer nofollow">@alicia-luettgen</a>.</p>'
|
|
expect(editor.getHTML()).toEqual(expected)
|
|
})
|
|
})
|
|
|
|
describe('`content` contains a hashtag', () => {
|
|
beforeEach(() => {
|
|
content =
|
|
'<p>This is a post content with a hashtag <a class="hashtag" href="/search/hashtag/metoo" target="_blank">#metoo</a>.</p>'
|
|
})
|
|
|
|
it('renders hashtag as link', () => {
|
|
const editor = createEditor()
|
|
const expected =
|
|
'<p>This is a post content with a hashtag <a href="/search/hashtag/metoo" rel="noopener noreferrer nofollow">#metoo</a>.</p>'
|
|
expect(editor.getHTML()).toEqual(expected)
|
|
})
|
|
})
|
|
|
|
describe('`content` contains embed code', () => {
|
|
beforeEach(() => {
|
|
content =
|
|
'<p>Baby loves cat: </p><a href="https://www.youtube.com/watch?v=qkdXAtO40Fo" class="embed" target="_blank"></a>'
|
|
})
|
|
|
|
it('recognizes embed code', () => {
|
|
const editor = createEditor()
|
|
const expected = {
|
|
content: [
|
|
{
|
|
content: [
|
|
{
|
|
text: 'Baby loves cat:',
|
|
type: 'text',
|
|
},
|
|
],
|
|
type: 'paragraph',
|
|
},
|
|
{
|
|
content: [
|
|
{
|
|
attrs: {
|
|
dataEmbedUrl: 'https://www.youtube.com/watch?v=qkdXAtO40Fo',
|
|
},
|
|
type: 'embed',
|
|
},
|
|
],
|
|
type: 'paragraph',
|
|
},
|
|
],
|
|
type: 'doc',
|
|
}
|
|
expect(editor.getJSON()).toEqual(expected)
|
|
})
|
|
})
|
|
})
|