fix(useMarkdown): fix parsing multiple links
Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2552>
This commit is contained in:
parent
fc979983ca
commit
b64ca34fd7
|
@ -6,7 +6,7 @@ import showdown from 'showdown'
|
|||
|
||||
showdown.extension('openExternalInNewTab', {
|
||||
type: 'output',
|
||||
regex: /<a.+?href.+">/g,
|
||||
regex: /<a.+?href.+?">/g,
|
||||
replace(text: string) {
|
||||
const matches = text.match(/href="(.+)">/) ?? []
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import { useMarkdownRaw } from '~/composables/useMarkdown'
|
||||
|
||||
describe('useMarkdownRaw', () => {
|
||||
describe('anchors', () => {
|
||||
it('should add target="_blank" to external links', () => {
|
||||
const html = useMarkdownRaw('https://open.audio')
|
||||
expect(html).toBe('<p><a href="https://open.audio" target="_blank" rel="noopener noreferrer">https://open.audio</a></p>')
|
||||
})
|
||||
|
||||
it('should not link raw path', () => {
|
||||
const html = useMarkdownRaw('/library/tags')
|
||||
expect(html).toBe('<p>/library/tags</p>')
|
||||
})
|
||||
|
||||
it('should not add target="_blank" to internal links', () => {
|
||||
const html = useMarkdownRaw('[/library/tags](/library/tags)')
|
||||
expect(html).toBe('<p><a href="/library/tags">/library/tags</a></p>')
|
||||
})
|
||||
|
||||
it('should handle multiple links', () => {
|
||||
const html = useMarkdownRaw('https://open.audio https://funkwhale.audio')
|
||||
expect(html).toBe('<p><a href="https://open.audio" target="_blank" rel="noopener noreferrer">https://open.audio</a> <a href="https://funkwhale.audio" target="_blank" rel="noopener noreferrer">https://funkwhale.audio</a></p>')
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue