mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-28 08:31:25 +00:00
fix(frontend): simplify asciinema regex
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
215ceea72c
commit
3f8771a15e
2 changed files with 7 additions and 8 deletions
|
@ -25,6 +25,12 @@ describe('Replace asciinema link', () => {
|
|||
)
|
||||
})
|
||||
|
||||
it('will replace a valid URL with appendix', () => {
|
||||
expect(markdownIt.renderInline('https://asciinema.org/a/123981234?a=1')).toBe(
|
||||
`<app-asciinema id='123981234'></app-asciinema>`
|
||||
)
|
||||
})
|
||||
|
||||
it("won't replace an URL without path", () => {
|
||||
expect(markdownIt.renderInline('https://asciinema.org/123981234')).toBe(`https://asciinema.org/123981234`)
|
||||
})
|
||||
|
|
|
@ -8,14 +8,7 @@ import { AsciinemaMarkdownExtension } from './asciinema-markdown-extension'
|
|||
import type MarkdownIt from 'markdown-it'
|
||||
import markdownItRegex from 'markdown-it-regex'
|
||||
|
||||
const protocolRegex = /(?:http(?:s)?:\/\/)?/
|
||||
const domainRegex = /(?:asciinema\.org\/a\/)/
|
||||
const idRegex = /(\d+)/
|
||||
const tailRegex = /(?:[./?#].*)?/
|
||||
const asciinemaUrlRegex = new RegExp(
|
||||
`^(?:${protocolRegex.source}${domainRegex.source}${idRegex.source}${tailRegex.source})$`,
|
||||
'i'
|
||||
)
|
||||
const asciinemaUrlRegex = /^https?:\/\/asciinema\.org\/a\/(\d+)(?:\?.*)?$/i
|
||||
|
||||
const replaceAsciinemaLink: RegexOptions = {
|
||||
name: 'asciinema-link',
|
||||
|
|
Loading…
Reference in a new issue