-
-
Notifications
You must be signed in to change notification settings - Fork 361
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
add remark-embed-tag plugins.md #1305
Conversation
Signed-off-by: Yu Long <[email protected]>
Thanks @Reimirno! Some tips:
import type { Root } from "mdast"
import { visit } from "unist-util-visit";
// …
export default function remarkTagEmbed(configs: Config = {} as Config) {
configs = { ...defaultConfig, ...configs };
const transformer = (ast: Root) => {
visit(ast, "text", (node, index, parent) => {
if (index == null || !parent) {
return
}
const { value } = node;
if (configs.youtube) {
const youtube = parseYouTube(value);
if (youtube) {
parent[index] = {
type: 'html',
value: createsYouTubeWidget(youtube)
}
}
}
// …
});
};
return transformer;
} Or you could use import type { Root } from "mdast"
import type { Plugin } from "unified"
import { visit } from "unist-util-visit";
// …
const remarkTagEmbed: Plugin<[Configs?], Root> = (configs) => {
configs = { ...defaultConfig, ...configs };
return (ast) => {
visit(ast, "text", (node, index, parent) => {
if (index == null || !parent) {
return
}
const { value } = node;
if (configs.youtube) {
const youtube = parseYouTube(value);
if (youtube) {
parent[index] = {
type: 'html',
value: createsYouTubeWidget(youtube)
}
}
}
// …
});
};
}
export default remarkTagEmbed |
@remcohaszing Thank you so much for the detailed and prompt review!
|
remark is for mdast (markdown) to mdast. export default remarkTagEmbed
Just like in the remark plugin, you will probably need to iterate over all You can have a look at the rehype plugins list. If you’re interested in a TypeScript implementation specifically, you can have a look at
npm does not guarantee transitive dependencies are available or the same version unless they are in dependencies. pnpm explicitly makes sure it doesn’t work. Everything you import in your generated output, should be in your dependencies. So this includes |
Closing this, it’s better as a rehype plugin |
Initial checklist
Description of changes
Add
remark-embed-tag
to the plugin list.