Gathering detailed insights and metrics for @ipikuka/plugins
Gathering detailed insights and metrics for @ipikuka/plugins
Gathering detailed insights and metrics for @ipikuka/plugins
Gathering detailed insights and metrics for @ipikuka/plugins
npm install @ipikuka/plugins
Typescript
Module System
Node Version
NPM Version
TypeScript (99.56%)
JavaScript (0.44%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2 Stars
35 Commits
1 Branches
1 Contributors
Updated on Jun 10, 2025
Latest Version
1.0.2
Package Id
@ipikuka/plugins@1.0.2
Unpacked Size
53.95 kB
Size
15.67 kB
File Count
36
NPM Version
10.8.2
Node Version
20.18.1
Published on
Jan 26, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
28
22
This package is a collection of unified (remark, rehype and recma) plugins and rehype handlers for markdown / MDX that I used in my many projects.
unified is a project that transforms content with abstract syntax trees (ASTs) using the new parser micromark.
remark adds support for markdown to unified. mdast is the Markdown Abstract Syntax Tree (AST) which is a specification for representing markdown in a syntax tree.
rehype is a tool that transforms HTML with plugins. hast stands for HTML Abstract Syntax Tree (HAST) that rehype uses.
recma adds support for producing a javascript code by transforming esast which stands for Ecma Script Abstract Syntax Tree (AST) that is used in production of compiled source for MDX.
This package provides remarkPlugins
, rehypePlugins
, recmaPlugins
, and remarkRehypeOptions
for @mdx-js/mdx
and related projects like next-mdx-remote
and next-mdx-remote-client
.
If you don't want to install and configure any specific remark, rehype and recma plugin; @ipikuka/plugins
provides you a plugin list that is opinionated and well tested.
It also helps creating table of contents (TOC)
for markdown/mdx content out of the box via remark-flexible-toc
.
The remark plugins that exposed by @ipikuka/plugins
:
(exactly in specific order below)
The rehype plugins that exposed by @ipikuka/plugins
:
(exactly in specific order below)
The recma plugins (only for MDX content) that exposed by @ipikuka/plugins
:
(exactly in specific order below)
The rehype handlers that exposed by @ipikuka/plugins
:\
defListHastHandlers
from "remark-definition-list"html
handler for only markdown contentThis package is suitable for ESM only. In Node.js (version 16+), install with npm:
1npm install @ipikula/plugins
or
1yarn add @ipikula/plugins
Let's create a wrapper for serialize
function of next-mdx-remote-client
and use @ipikua/plugins inside.
1// serialize.ts 2 3import { serialize as serialize_ } from "next-mdx-remote-client/serialize"; 4import type { SerializeResult, SerializeProps } from "next-mdx-remote-client/serialize"; 5import { plugins, prepare, type TocItem } from "@ipikua/plugins"; 6 7export async function serialize< 8 TFrontmatter extends Record<string, unknown> = Record<string, unknown>, 9 TScope extends Record<string, unknown> = Record<string, unknown>, 10>({ 11 source, 12 options, 13}: SerializeProps<TScope>): Promise<SerializeResult<TFrontmatter, TScope & { toc?: TocItem[] }>> { 14 const { mdxOptions, ...rest } = options || {}; 15 16 const format_ = mdxOptions?.format; 17 const format = format_ === "md" || format_ === "mdx" ? format_ : "mdx"; 18 const processedSource = format === "mdx" ? prepare(source) : source; 19 20 return await serialize_<TFrontmatter, TScope>({ 21 source: processedSource, 22 options: { 23 mdxOptions: { 24 ...mdxOptions, 25 ...plugins({ format }), 26 }, 27 vfileDataIntoScope: "toc", 28 ...rest, 29 }, 30 }); 31};
Let's create another wrapper for serialize
function of next-mdx-remote
and use @ipikua/plugins inside.
1// serialize.ts 2 3import { serialize as serialize_, type SerializeOptions } from "next-mdx-remote/serialize"; 4import { plugins, prepare, type TocItem } from "@ipikua/plugins"; 5import { type Compatible } from "vfile"; 6 7export async function serialize< 8 TFrontmatter extends Record<string, unknown> = Record<string, unknown>, 9 TScope extends Record<string, unknown> = Record<string, unknown>, 10>( 11 source: Compatible, 12 { mdxOptions, parseFrontmatter, scope }: SerializeOptions = {}, 13): Promise<MDXRemoteSerializeResult<TScope & { toc?: TocItem[] }, TFrontmatter>> { 14 const toc: TocItem[] = []; 15 16 const { format: format_, ...rest } = mdxOptions || {}; 17 const format = format_ === "md" || format_ === "mdx" ? format_ : "mdx"; 18 const processedSource = format === "mdx" ? prepare(source) : source; 19 20 return await serialize_<TScope & { toc?: TocItem[] }, TFrontmatter>(processedSource, { 21 parseFrontmatter, 22 scope: { ...scope, toc }, 23 mdxOptions: { 24 format, 25 ...rest, 26 ...plugins({ format, toc }), 27 }, 28 }); 29};
You can use the serialize
wrappers in pages
router of nextjs
applications.
[!NOTE] I will try to provide a complete example
nextjs
applications later.
Thanks to @ipikuka/plugins
, the markdown/mdx content will support table of contents, containers, markers, aligned paragraphs, gfm syntax (tables, strikethrough, task lists, autolinks etc.), inserted texts, highlighted code fences, code titles, autolink for headers, definition lists etc. in addition to standard markdown syntax like bold texts, italic texts, lists, blockquotes, headings etc.
Without @ipikua/plugins
the result would be a standart markdown result with no containers, no markers, no gfm syntax, no inserted texts, no highlighted code fences etc.
1type PluginOptions = { 2 format?: CompileOptions["format"]; 3 toc?: TocItem[]; 4};
It is "md" | "mdx" | "detect" | null | undefined
option to adjust remark plugins and whether or not to employ recma plugins.
It is optional, and default is mdx
.
It is TocItem[]
option to compose a table of content by remark-flexible-toc
.
It is optional and have no default value.
If you want to have a table of content and supplied into the scope
, I advise you use the option toc
if you use next-mdx-remote
, but you don't need it for next-mdx-remote-client
thanks to the option vfileDataIntoScope: "toc"
.
@mdx-js/mdx
1import { compile } from "@mdx-js/mdx"; 2import { plugins, type TocItem } from "@ipikua/plugins"; 3 4// ... 5const toc: TocItem[] = []; // if you don't need a table of content then you can omit it. 6 7const compiledSource = await compile(source, { 8 ...plugins({ format: "md", toc }), 9}) 10 11console.log(toc); // now it has table of contents 12 13// ...
next-mdx-remote-client
1import { serialize } from "next-mdx-remote-client/serialize"; 2import { plugins } from "@ipikua/plugins"; 3 4// ... 5const mdxSource = await serialize<TFrontmatter, TScope>({ 6 source, 7 options: { 8 mdxOptions: { 9 ...plugins({ format: "md" }), 10 }, 11 parseFrontmatter: true, 12 scope: {}, 13 vfileDataIntoScope: "toc", // it will ensure the scope has `toc` 14 }, 15}); 16 17console.log(mdxSource.scope.toc); // now it has table of contents 18 19// ...
next-mdx-remote
1import { serialize } from "next-mdx-remote/serialize"; 2import { plugins, type TocItem } from "@ipikua/plugins"; 3 4// ... 5const toc: TocItem[] = []; // if you don't need a table of content then you can omit it. 6 7const mdxSource = await serialize<TScope, TFrontmatter>( 8 source, 9 { 10 mdxOptions: { 11 ...plugins({ format: "md", toc }), 12 }, 13 parseFrontmatter: true, 14 scope: { toc }, 15 }, 16); 17 18console.log(mdxSource.scope.toc); // now it has table of contents 19 20// ...
The package exposes one utility function which is called prepare
.
It is for MDX source (not markdown) to correct breaklines to <br/>
, horizontal lines to <hr/>
, guillements to « »
and or equals signs to ≤
and ≥
. The prepare
function accepts Compatible
(see vfile
) but check if it is string
, otherwise do nothing.
The reason for having prepare
function is that remark parser for markdown content and mdx parser for mdx content are different.
The plugins modifies the mdast
(Markdown abstract syntax tree), the hast
(HTML abstract syntax tree) and the esast
(EcmaScript abstract syntax tree).
This package is fully typed with TypeScript.
The package exports the type PluginOptions
, CompileOptions
, TocItem
.
The plugins that are provided by this package work with unified
version 6+
, MDX
version 2+
, next-mdx-remote
version canary
, next-mdx-remote-client
version 1+
.
Use of some rehype plugins involves hast, but doesn't lead to cross-site scripting (XSS) attacks.
I like to contribute the Unified / Remark / MDX ecosystem, so I recommend you to have a look my plugins.
remark-flexible-code-titles
– Remark plugin to add titles or/and containers for the code blocks with customizable propertiesremark-flexible-containers
– Remark plugin to add custom containers with customizable properties in markdownremark-ins
– Remark plugin to add ins
element in markdownremark-flexible-paragraphs
– Remark plugin to add custom paragraphs with customizable properties in markdownremark-flexible-markers
– Remark plugin to add custom mark
element with customizable properties in markdownremark-flexible-toc
– Remark plugin to expose the table of contents via vfile.data
or via an option referenceremark-mdx-remove-esm
– Remark plugin to remove import and/or export statements (mdxjsEsm)rehype-pre-language
– Rehype plugin to add language information as a property to pre
elementrecma-mdx-escape-missing-components
– Recma plugin to set the default value () => null
for the Components in MDX in case of missing or not provided so as not to throw an errorrecma-mdx-change-props
– Recma plugin to change the props
parameter into the _props
in the function _createMdxContent(props) {/* */}
in the compiled source in order to be able to use {props.foo}
like expressions. It is useful for the next-mdx-remote
or next-mdx-remote-client
users in nextjs
applications.MIT License © ipikuka
🟩 unified 🟩 remark 🟩 remark plugin 🟩 mdast 🟩 rehype 🟩 rehype plugin 🟩 hast 🟩 recma 🟩 recma plugin 🟩 esast 🟩 markdown 🟩 mdx
No vulnerabilities found.
No security vulnerabilities found.