-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prism highlighted line breaking (#1029)
Co-authored-by: Anthony Fu <[email protected]>
- Loading branch information
1 parent
0390ee7
commit 4845174
Showing
5 changed files
with
155 additions
and
21 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`markdown-it-prism > should render multi-line JS strings and comments correctly 1`] = ` | ||
"<pre class=\\"slidev-code language-js\\"><code><span class=\\"line\\"><span class=\\"token template-string\\"><span class=\\"token template-punctuation string\\">\`</span><span class=\\"token string\\">Multi</span></span></span> | ||
<span class=\\"line\\"><span class=\\"token string\\"><span class=\\"token template-string\\">line</span><span class=\\"token template-punctuation string\\">\`</span></span></span> | ||
<span class=\\"line\\"><span class=\\"token comment\\">/**</span></span> | ||
<span class=\\"line\\"><span class=\\"token comment\\"> * Hello</span></span> | ||
<span class=\\"line\\"><span class=\\"token comment\\"> */</span></span></code></pre> | ||
" | ||
`; | ||
exports[`markdown-it-prism > should render multi-line XML nodes correctly 1`] = ` | ||
"<pre class=\\"slidev-code language-xml\\"><code><span class=\\"line\\"><span class=\\"token tag\\"><span class=\\"token tag\\"><span class=\\"token punctuation\\"><</span>a</span><span class=\\"token punctuation\\">/></span></span></span> | ||
<span class=\\"line\\"><span class=\\"token tag\\"><span class=\\"token tag\\"><span class=\\"token punctuation\\"><</span>b</span></span></span> | ||
<span class=\\"line\\"><span class=\\"token tag\\"> <span class=\\"token attr-name\\">attr</span><span class=\\"token attr-value\\"><span class=\\"token punctuation attr-equals\\">=</span><span class=\\"token punctuation\\">\\"</span>value<span class=\\"token punctuation\\">\\"</span></span></span></span> | ||
<span class=\\"line\\"><span class=\\"token tag\\"><span class=\\"token punctuation\\">/></span></span></span></code></pre> | ||
" | ||
`; | ||
exports[`markdown-it-prism > should render non-multiline statements correctly 1`] = ` | ||
"<pre class=\\"slidev-code language-ts\\"><code><span class=\\"line\\"><span class=\\"token keyword\\">const</span> a <span class=\\"token operator\\">=</span> <span class=\\"token number\\">1</span><span class=\\"token punctuation\\">;</span></span> | ||
<span class=\\"line\\"><span class=\\"token keyword\\">const</span> b <span class=\\"token operator\\">=</span> <span class=\\"token number\\">2</span><span class=\\"token punctuation\\">;</span></span> | ||
<span class=\\"line\\"><span class=\\"token keyword\\">const</span> c <span class=\\"token operator\\">=</span> a <span class=\\"token operator\\">+</span> b<span class=\\"token punctuation\\">;</span></span></code></pre> | ||
" | ||
`; |
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,47 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import Markdown from 'markdown-it' | ||
import markdownItPrism from '../packages/slidev/node/plugins/markdown-it-prism' | ||
|
||
describe('markdown-it-prism', () => { | ||
const md = Markdown() | ||
markdownItPrism(md, { plugins: [], init: () => {} }) | ||
|
||
it('should render multi-line JS strings and comments correctly', () => { | ||
const text = ` | ||
\`\`\`js | ||
\`Multi | ||
line\` | ||
/** | ||
* Hello | ||
*/ | ||
\`\`\` | ||
` | ||
const actual = md.render(text) | ||
expect(actual).toMatchSnapshot() | ||
}) | ||
|
||
it('should render multi-line XML nodes correctly', () => { | ||
const text = ` | ||
\`\`\`xml | ||
<a/> | ||
<b | ||
attr="value" | ||
/> | ||
\`\`\` | ||
` | ||
const actual = md.render(text) | ||
expect(actual).toMatchSnapshot() | ||
}) | ||
|
||
it('should render non-multiline statements correctly', () => { | ||
const text = ` | ||
\`\`\`ts | ||
const a = 1; | ||
const b = 2; | ||
const c = a + b; | ||
\`\`\` | ||
` | ||
const actual = md.render(text) | ||
expect(actual).toMatchSnapshot() | ||
}) | ||
}) |