fix(frontend): simplify asciinema regex

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-02-06 12:11:51 +01:00
parent 215ceea72c
commit 3f8771a15e
2 changed files with 7 additions and 8 deletions

View file

@ -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`)
})

View file

@ -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',