Skip to content

Commit

Permalink
fix(markdown): replace double quotation marks in classname(fix #3152) (
Browse files Browse the repository at this point in the history
…#3154)

Co-authored-by: xuze <[email protected]>
  • Loading branch information
spencerHT and xuze authored Aug 14, 2023
1 parent 9044f14 commit cef64e6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`preWrapper should wrap code with double quotation marks 1`] = `
<!--beforebegin-->
<div class="language-js name='marks' extra-class">
<!--afterbegin--><pre><code class="language-js">new Vue()
</code></pre>
<!--beforeend-->
</div>
<!--afterend-->
`;

exports[`preWrapper should wrap code with quadruple space 1`] = `
<!--beforebegin-->
<div class="language- extra-class">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``` js name="marks"
new Vue()
```
6 changes: 6 additions & 0 deletions packages/@vuepress/markdown/__tests__/preWrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ describe('preWrapper', () => {
expect(output1 === output2).toBe(false)
expect(output2).toMatchSnapshot()
})

test('should wrap code with double quotation marks', () => {
const input = getFragment(__dirname, 'code-prewrapper-with-double-quotation-marks.md')
const output2 = mdP.render(input)
expect(output2).toMatchSnapshot()
})
})
3 changes: 2 additions & 1 deletion packages/@vuepress/markdown/lib/preWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = md => {
const [tokens, idx] = args
const token = tokens[idx]
const rawCode = wrapped(...args)
return `<!--beforebegin--><div class="language-${token.info.trim()} extra-class">`
const tokenInfo = token.info.trim().replace(/\"/g, '\'')
return `<!--beforebegin--><div class="language-${tokenInfo} extra-class">`
+ `<!--afterbegin-->${rawCode}<!--beforeend--></div><!--afterend-->`
}
const { fence, code_block: codeBlock } = md.renderer.rules
Expand Down

0 comments on commit cef64e6

Please sign in to comment.