Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where rehypePlugins were not passed through all the way through to the markdown compiler #1693

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/ember-repl/addon/src/compile/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export async function compileMD(
importMap?: EvalImportMap;
topLevelScope?: ScopeMap;
remarkPlugins?: UnifiedPlugin[];
rehypePlugins?: UnifiedPlugin[];
CopyComponent?: string;
ShadowComponent?: string;
}
Expand All @@ -114,6 +115,7 @@ export async function compileMD(
CopyComponent: options?.CopyComponent,
ShadowComponent: options?.ShadowComponent,
remarkPlugins: options?.remarkPlugins,
rehypePlugins: options?.rehypePlugins,
});

rootTemplate = templateOnlyGlimdown;
Expand Down
1 change: 1 addition & 0 deletions packages/ember-repl/addon/src/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const SUPPORTED_FORMATS = ['glimdown', 'gjs', 'hbs'];
interface GlimdownOptions extends Scope, Events {
format: 'glimdown';
remarkPlugins?: UnifiedPlugin[];
rehypePlugins?: UnifiedPlugin[];
CopyComponent?: string;
ShadowComponent?: string;
topLevelScope?: ScopeMap;
Expand Down
88 changes: 88 additions & 0 deletions packages/ember-repl/test-app/tests/rendering/markdown-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,93 @@ module('Rendering | compile()', function (hooks) {

assert.dom().containsText(text);
});

test('adding a remark plugin', async function (assert) {
setupOnerror((e) => {
console.error(e);
assert.notOk('This should not error');
});

let snippet = '# Hello';

let component: ComponentLike | undefined;

await compile(snippet, {
format: 'glimdown',
onSuccess: (comp) => (component = comp),
onError: (e) => {
console.error(e);
assert.notOk('did not expect error');
},
onCompileStart: () => {
/* not used */
},

remarkPlugins: [
function noH1(/* options */) {
return (tree) => {
return visit(tree, ['heading'], function (node) {
if (!('depth' in node)) return;

if (node.depth === 1) {
node.depth = 2;
}

return 'skip';
});
};
},
],
});

debugAssert(`[BUG]`, component);

await render(component);

assert.dom('h2').containsText('Hello');
});
test('adding a rehype plugin', async function (assert) {
setupOnerror((e) => {
console.error(e);
assert.notOk('This should not error');
});

let snippet = '# Hello';

let component: ComponentLike | undefined;

await compile(snippet, {
format: 'glimdown',
onSuccess: (comp) => (component = comp),
onError: (e) => {
console.error(e);
assert.notOk('did not expect error');
},
onCompileStart: () => {
/* not used */
},
rehypePlugins: [
function noH1(/* options */) {
return (tree) => {
return visit(tree, ['element'], function (node) {
if (!('tagName' in node)) return;

if (node.tagName === 'h1') {
node.tagName = 'h2';
}

return 'skip';
});
};
},
],
});

debugAssert(`[BUG]`, component);

await render(component);

assert.dom('h2').containsText('Hello');
});
});
});
Loading