-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't escape markdown underscores (#4896)
- Loading branch information
Showing
5 changed files
with
74 additions
and
22,500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { htmlFromMarkdown, markdownFromHTML } from './markdown'; | ||
|
||
describe('markdownFromHTML', () => { | ||
test('should convert HTML to markdown', () => { | ||
const html = '<p>Text <strong>Bold</strong> <em>italic</em></p>'; | ||
const markdown = markdownFromHTML(html); | ||
expect(markdown).toMatchInlineSnapshot(` | ||
"Text **Bold** *italic* | ||
" | ||
`); | ||
}); | ||
|
||
test('should not escape mention handles with _', () => { | ||
const html = | ||
'<p>A normal handle: <span>@lens/foo</span></p>' + | ||
'<p>A handle with underscore: <span>@lens/foo_bar</span></p>'; | ||
const markdown = markdownFromHTML(html); | ||
expect(markdown).toContain('@lens/foo'); | ||
expect(markdown).toContain('@lens/foo_bar'); | ||
expect(markdown).toMatchInlineSnapshot(` | ||
"A normal handle: @lens/foo | ||
A handle with underscore: @lens/foo_bar | ||
" | ||
`); | ||
}); | ||
}); | ||
|
||
describe('htmlFromMarkdown', () => { | ||
test('should convert markdown to HTML', () => { | ||
const markdown = 'Text **Bold** _italic_'; | ||
const html = htmlFromMarkdown(markdown); | ||
expect(html).toMatchInlineSnapshot(` | ||
"<p>Text <strong>Bold</strong> <em>italic</em></p> | ||
" | ||
`); | ||
}); | ||
|
||
test('should not escape mention handles with _', () => { | ||
const markdown = [ | ||
'A normal handle: @lens/foo', | ||
'A handle with underscore: @lens/foo_bar' | ||
].join('\n\n'); | ||
const html = htmlFromMarkdown(markdown); | ||
expect(html).toMatchInlineSnapshot(` | ||
"<p>A normal handle: @lens/foo</p> | ||
<p>A handle with underscore: @lens/foo_bar</p> | ||
" | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
alias: { '@helpers': '/src/helpers' }, | ||
globals: true, | ||
testTimeout: 30000 | ||
} | ||
}); |
Oops, something went wrong.