Skip to content

Commit fbd6a2a

Browse files
Fix issue where rehypePlugins were not passed through all the way through to the markdown compiler (#1693)
* Fix issue where rehypePlugins were not passed through all the way through to the markdown compiler * Also update types
1 parent 778c3d4 commit fbd6a2a

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

packages/ember-repl/addon/src/compile/formats.ts

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export async function compileMD(
9090
importMap?: EvalImportMap;
9191
topLevelScope?: ScopeMap;
9292
remarkPlugins?: UnifiedPlugin[];
93+
rehypePlugins?: UnifiedPlugin[];
9394
CopyComponent?: string;
9495
ShadowComponent?: string;
9596
}
@@ -114,6 +115,7 @@ export async function compileMD(
114115
CopyComponent: options?.CopyComponent,
115116
ShadowComponent: options?.ShadowComponent,
116117
remarkPlugins: options?.remarkPlugins,
118+
rehypePlugins: options?.rehypePlugins,
117119
});
118120

119121
rootTemplate = templateOnlyGlimdown;

packages/ember-repl/addon/src/compile/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];
2929
interface GlimdownOptions extends Scope, Events {
3030
format: 'glimdown';
3131
remarkPlugins?: UnifiedPlugin[];
32+
rehypePlugins?: UnifiedPlugin[];
3233
CopyComponent?: string;
3334
ShadowComponent?: string;
3435
topLevelScope?: ScopeMap;

packages/ember-repl/test-app/tests/rendering/markdown-test.gts

+88
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,93 @@ module('Rendering | compile()', function (hooks) {
239239

240240
assert.dom().containsText(text);
241241
});
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+
});
242330
});
243331
});

0 commit comments

Comments
 (0)