1
1
import { module , test } from 'qunit' ;
2
2
3
+ import rehypeShiki from '@shikijs/rehype' ;
3
4
import { stripIndent } from 'common-tags' ;
4
5
import { invocationOf , nameFor } from 'ember-repl' ;
5
6
import { parseMarkdown } from 'ember-repl/formats/markdown' ;
@@ -10,13 +11,7 @@ import { visit } from 'unist-util-visit';
10
11
* indentation are stripped
11
12
*/
12
13
function assertOutput ( actual : string , expected : string ) {
13
- let _actual = actual
14
- . split ( '\n' )
15
- . filter ( Boolean )
16
- . join ( '\n' )
17
- . trim ( )
18
- . replace ( / < d i v c l a s s = " g l i m d o w n - r e n d e r " > / , '' )
19
- . replace ( / < \/ d i v > / , '' ) ;
14
+ let _actual = actual . split ( '\n' ) . filter ( Boolean ) . join ( '\n' ) . trim ( ) ;
20
15
let _expected = expected . split ( '\n' ) . filter ( Boolean ) . join ( '\n' ) . trim ( ) ;
21
16
22
17
QUnit . assert . equal ( _actual , _expected ) ;
@@ -60,7 +55,7 @@ module('Unit | parseMarkdown()', function () {
60
55
<h1>Title</h1>
61
56
62
57
<div class=\"glimdown-snippet relative\"><pre><code class=\"language-js\"> const two = 2;
63
- </code></pre><CopyMenu />
58
+ </code></pre><CopyMenu /></div>
64
59
`
65
60
) ;
66
61
@@ -178,6 +173,38 @@ module('Unit | parseMarkdown()', function () {
178
173
179
174
assert . deepEqual ( result . blocks , [ ] ) ;
180
175
} ) ;
176
+
177
+ test ( 'rehypePlugins retain {{ }} escaping' , async function ( ) {
178
+ let result = await parseMarkdown (
179
+ stripIndent `
180
+ # Title
181
+
182
+ \`\`\`gjs
183
+ const two = 2
184
+
185
+ <template>
186
+ {{two}}
187
+ </template>
188
+ \`\`\`
189
+ ` ,
190
+ {
191
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
192
+ rehypePlugins : [ [ rehypeShiki as any , { theme : 'github-dark' } ] ] ,
193
+ }
194
+ ) ;
195
+
196
+ assertOutput (
197
+ result . templateOnlyGlimdown ,
198
+ `<h1>Title</h1>
199
+ <div class="glimdown-snippet relative"><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> two</span><span style="color:#F97583"> =</span><span style="color:#79B8FF"> 2</span></span>
200
+ <span class="line"></span>
201
+ <span class="line"><span style="color:#E1E4E8"><</span><span style="color:#85E89D">template</span><span style="color:#E1E4E8">></span></span>
202
+ <span class="line"><span style="color:#F97583"> \\{{</span><span style="color:#79B8FF">two</span><span style="color:#F97583">}}</span></span>
203
+ <span class="line"><span style="color:#E1E4E8"></</span><span style="color:#85E89D">template</span><span style="color:#E1E4E8">></span></span>
204
+ <span class="line"></span></code></pre></div>
205
+ `
206
+ ) ;
207
+ } ) ;
181
208
} ) ;
182
209
183
210
module ( 'hbs' , function ( ) {
@@ -199,7 +226,7 @@ module('Unit | parseMarkdown()', function () {
199
226
stripIndent `
200
227
<h1>Title</h1>
201
228
202
- ${ invocationOf ( name ) }
229
+ <div class=\"glimdown-render\"> ${ invocationOf ( name ) } </div>
203
230
`
204
231
) ;
205
232
@@ -232,7 +259,7 @@ module('Unit | parseMarkdown()', function () {
232
259
<h1>Title</h1>
233
260
234
261
<div class=\"glimdown-snippet relative\"><pre><code class=\"language-gjs\"> const two = 2;
235
- </code></pre><CopyMenu />
262
+ </code></pre><CopyMenu /></div>
236
263
`
237
264
) ;
238
265
@@ -255,7 +282,7 @@ module('Unit | parseMarkdown()', function () {
255
282
stripIndent `
256
283
<h1>Title</h1>
257
284
258
- ${ invocationOf ( name ) }
285
+ <div class=\"glimdown-render\"> ${ invocationOf ( name ) } </div>
259
286
`
260
287
) ;
261
288
@@ -268,6 +295,34 @@ module('Unit | parseMarkdown()', function () {
268
295
] ) ;
269
296
} ) ;
270
297
298
+ test ( 'Code with preview fence has {{ }} tokens escaped' , async function ( ) {
299
+ let result = await parseMarkdown ( stripIndent `
300
+ # Title
301
+
302
+ \`\`\`gjs
303
+ const two = 2
304
+
305
+ <template>
306
+ {{two}}
307
+ </template>
308
+ \`\`\`
309
+ ` ) ;
310
+
311
+ assertOutput (
312
+ result . templateOnlyGlimdown ,
313
+ stripIndent `
314
+ <h1>Title</h1>
315
+
316
+ <div class=\"glimdown-snippet relative\"><pre><code class=\"language-gjs\">const two = 2
317
+
318
+ <template>
319
+ \\{{two}}
320
+ </template>
321
+ </code></pre></div>
322
+ `
323
+ ) ;
324
+ } ) ;
325
+
271
326
test ( 'Can invoke a component again when defined in a live fence' , async function ( assert ) {
272
327
let snippet = `const two = 2` ;
273
328
let name = nameFor ( snippet ) ;
@@ -285,7 +340,7 @@ module('Unit | parseMarkdown()', function () {
285
340
stripIndent `
286
341
<h1>Title</h1>
287
342
288
- ${ invocationOf ( name ) }
343
+ <div class=\"glimdown-render\"> ${ invocationOf ( name ) } </div>
289
344
<Demo />
290
345
`
291
346
) ;
@@ -319,7 +374,7 @@ module('Unit | parseMarkdown()', function () {
319
374
stripIndent `
320
375
<p>hi</p>
321
376
322
- ${ invocationOf ( name ) }
377
+ <div class=\"glimdown-render\"> ${ invocationOf ( name ) } </div>
323
378
<div class=\"glimdown-snippet relative\"><pre><code class=\"language-gjs\">import Component from '@glimmer/component';
324
379
import { on } from '@ember/modifier';
325
380
<template>
0 commit comments