Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/components/Markdown/Markdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ describe('Markdown', () => {
expect(getByRole('link').getAttribute('href')).toBe('https://hyperparam.app')
})

it('renders a partial link', () => {
const text = 'Check out [Hyp](https://hyper'
const { getByText, queryByText } = render(<Markdown text={text} />)
expect(getByText('Hyp')).toBeDefined()
expect(queryByText('hyper')).toBeNull()
expect(getByText('Hyp').tagName).toBe('A')
})

it('renders multiple links in one line', () => {
const text = 'Check out [Hyp](https://hyperparam.app) on [GitHub](https://github.com/hyparam).'
const { getAllByRole, getByText } = render(<Markdown text={text} />)
Expand Down
5 changes: 4 additions & 1 deletion src/components/Markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ function parseInlineRecursive(text: string, stop?: string): [Token[], number] {
i++ // skip '('
const endParen = text.indexOf(')', i)
if (endParen === -1) {
tokens.push({ type: 'text', content: text.slice(start, i) })
// No closing ")": assume in-flight href
const href = text.slice(i).trim()
i = text.length // consume to EOI so loop terminates
tokens.push({ type: 'link', href, children: linkTextTokens })
continue
}
const href = text.slice(i, endParen).trim()
Expand Down