File tree Expand file tree Collapse file tree 5 files changed +54
-3
lines changed
packages/@vuepress/markdown Expand file tree Collapse file tree 5 files changed +54
-3
lines changed Original file line number Diff line number Diff line change 1+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+ exports [` preWrapper should wrap code with quadruple space 1` ] = `
4+ <!--beforebegin-->
5+ <div class = " language- extra-class" >
6+ <!--afterbegin--><pre ><code >new Vue()
7+ </code ></pre >
8+ <!--beforeend-->
9+ </div >
10+ <!--afterend-->
11+ ` ;
12+
13+ exports [` preWrapper should wrap code with triple back quote 1` ] = `
14+ <!--beforebegin-->
15+ <div class = " language-js extra-class" >
16+ <!--afterbegin--><pre ><code class = " language-js" >new Vue()
17+ </code ></pre >
18+ <!--beforeend-->
19+ </div >
20+ <!--afterend-->
21+ ` ;
Original file line number Diff line number Diff line change 1+ ``` js
2+ new Vue ()
3+ ```
Original file line number Diff line number Diff line change 1+ new Vue()
Original file line number Diff line number Diff line change 1+ import { getFragment } from '@vuepress/test-utils'
2+ import { Md } from './util'
3+ import preWrapper from '../lib/preWrapper.js'
4+
5+ const md = Md ( )
6+ const mdP = Md ( ) . use ( preWrapper )
7+
8+ describe ( 'preWrapper' , ( ) => {
9+ test ( 'should wrap code with triple back quote' , ( ) => {
10+ const input = getFragment ( __dirname , 'code-prewrapper-with-quotes.md' )
11+ const output1 = md . render ( input )
12+ const output2 = mdP . render ( input )
13+ expect ( output1 === output2 ) . toBe ( false )
14+ expect ( output2 ) . toMatchSnapshot ( )
15+ } )
16+
17+ test ( 'should wrap code with quadruple space' , ( ) => {
18+ const input = getFragment ( __dirname , 'code-prewrapper-with-spaces.md' )
19+ const output1 = md . render ( input )
20+ const output2 = mdP . render ( input )
21+ expect ( output1 === output2 ) . toBe ( false )
22+ expect ( output2 ) . toMatchSnapshot ( )
23+ } )
24+ } )
Original file line number Diff line number Diff line change 88// 4. <!--afterend-->
99
1010module . exports = md => {
11- const fence = md . renderer . rules . fence
12- md . renderer . rules . fence = ( ...args ) => {
11+ const wrap = ( wrapped ) => ( ...args ) => {
1312 const [ tokens , idx ] = args
1413 const token = tokens [ idx ]
15- const rawCode = fence ( ...args )
14+ const rawCode = wrapped ( ...args )
1615 return `<!--beforebegin--><div class="language-${ token . info . trim ( ) } extra-class">`
1716 + `<!--afterbegin-->${ rawCode } <!--beforeend--></div><!--afterend-->`
1817 }
18+ const { fence, code_block : codeBlock } = md . renderer . rules
19+ md . renderer . rules . fence = wrap ( fence )
20+ md . renderer . rules . code_block = wrap ( codeBlock )
1921}
You can’t perform that action at this time.
0 commit comments