@@ -239,5 +239,93 @@ module('Rendering | compile()', function (hooks) {
239
239
240
240
assert .dom ().containsText (text );
241
241
});
242
+
243
+ test (' adding a remark plugin' , async function (assert ) {
244
+ setupOnerror ((e ) => {
245
+ console .error (e );
246
+ assert .notOk (' This should not error' );
247
+ });
248
+
249
+ let snippet = ' # Hello' ;
250
+
251
+ let component: ComponentLike | undefined ;
252
+
253
+ await compile (snippet , {
254
+ format: ' glimdown' ,
255
+ onSuccess : (comp ) => (component = comp ),
256
+ onError : (e ) => {
257
+ console .error (e );
258
+ assert .notOk (' did not expect error' );
259
+ },
260
+ onCompileStart : () => {
261
+ /* not used */
262
+ },
263
+
264
+ remarkPlugins: [
265
+ function noH1(/* options */ ) {
266
+ return (tree ) => {
267
+ return visit (tree , [' heading' ], function (node ) {
268
+ if (! (' depth' in node )) return ;
269
+
270
+ if (node .depth === 1 ) {
271
+ node .depth = 2 ;
272
+ }
273
+
274
+ return ' skip' ;
275
+ });
276
+ };
277
+ },
278
+ ],
279
+ });
280
+
281
+ debugAssert (` [BUG] ` , component );
282
+
283
+ await render (component );
284
+
285
+ assert .dom (' h2' ).containsText (' Hello' );
286
+ });
287
+ test (' adding a rehype plugin' , async function (assert ) {
288
+ setupOnerror ((e ) => {
289
+ console .error (e );
290
+ assert .notOk (' This should not error' );
291
+ });
292
+
293
+ let snippet = ' # Hello' ;
294
+
295
+ let component: ComponentLike | undefined ;
296
+
297
+ await compile (snippet , {
298
+ format: ' glimdown' ,
299
+ onSuccess : (comp ) => (component = comp ),
300
+ onError : (e ) => {
301
+ console .error (e );
302
+ assert .notOk (' did not expect error' );
303
+ },
304
+ onCompileStart : () => {
305
+ /* not used */
306
+ },
307
+ rehypePlugins: [
308
+ function noH1(/* options */ ) {
309
+ return (tree ) => {
310
+ return visit (tree , [' element' ], function (node ) {
311
+ if (! (' tagName' in node )) return ;
312
+
313
+ if (node .tagName === ' h1' ) {
314
+ node .tagName = ' h2' ;
315
+ }
316
+
317
+ return ' skip' ;
318
+ });
319
+ };
320
+ },
321
+ ],
322
+ });
323
+
324
+ debugAssert (` [BUG] ` , component );
325
+
326
+ await render (component );
327
+
328
+ assert .dom (' h2' ).containsText (' Hello' );
329
+ });
242
330
});
243
331
});
0 commit comments