Gathering detailed insights and metrics for remark-flexible-containers
Gathering detailed insights and metrics for remark-flexible-containers
Gathering detailed insights and metrics for remark-flexible-containers
Gathering detailed insights and metrics for remark-flexible-containers
Remark plugin to add custom containers with customizable properties in markdown
npm install remark-flexible-containers
Typescript
Module System
Node Version
NPM Version
TypeScript (98.22%)
JavaScript (1.78%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
20 Stars
84 Commits
1 Forks
1 Branches
1 Contributors
Updated on Jun 05, 2025
Latest Version
1.3.0
Package Id
remark-flexible-containers@1.3.0
Unpacked Size
82.08 kB
Size
18.97 kB
File Count
8
NPM Version
10.8.2
Node Version
20.19.1
Published on
Jun 05, 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
5
1
This package is a unified (remark) plugin to add custom containers with customizable properties in markdown.
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.
This plugin is a remark plugin that transforms the mdast.
This plugin is useful if you want to add a custom container in markdown, for example, in order to produce a callout or admonition.
container
node, with custom tag name, custom class name and also additional properties.title
node inside the container, if the title is provided, with custom tag name, custom class name and also additional properties.This plugin doesn't support nested containers yet.
This package is suitable for ESM only. In Node.js (version 16+), install with npm:
1npm install remark-flexible-containers
or
1yarn add remark-flexible-containers
Say we have the following file, example.md
, which consists a flexible container. The container type is "warning", specified after the triple colon :::
; and the container title is "title". Each container should be closed with the triple colon :::
at the end.
1::: warning title 2My paragraph with **bold text** 3:::
[!TIP] You don't need to put empty lines inside the container.
[!CAUTION] There must be empty lines before and after the container in order to parse the markdown properly.
1<!--- here must be empty line ---> 2::: warning Title 3My paragraph with **bold text** 4::: 5<!--- here must be empty line --->
And our module, example.js
, looks as follows:
1import { read } from "to-vfile"; 2import remark from "remark"; 3import gfm from "remark-gfm"; 4import remarkRehype from "remark-rehype"; 5import rehypeStringify from "rehype-stringify"; 6import remarkFlexibleContainers from "remark-flexible-containers"; 7 8main(); 9 10async function main() { 11 const file = await remark() 12 .use(gfm) 13 .use(remarkFlexibleContainers) 14 .use(remarkRehype) 15 .use(rehypeStringify) 16 .process(await read("example.md")); 17 18 console.log(String(file)); 19}
Now, running node example.js
yields:
(The type
of the container is also added as a class name into the container
node and the title
node)
1<div class="remark-container warning"> 2 <div class="remark-container-title warning">Title</div> 3 <p>My paragraph with <strong>bold text</strong></p> 4</div>
Without remark-flexible-containers
, you’d get:
1<p>::: warning Title 2My paragraph with <strong>bold text</strong> 3:::</p>
As of version ^1.2.0
, the remark-flexible-containers
supports syntax for specific identifiers (tagname
, id
, classnames
) for individual container
and title
node. For example:
1::: info {section#foo.myclass} Title Of Information {span#baz.someclass} 2<!-- content --> 3:::
1<section class="remark-container info myclass" id="foo"> 2 <span class="remark-container-title info someclass" id="baz"> 3 Title Of Information 4 </span> 5 <!-- content --> 6</section>
For more information, go to detailed explanation placed after the "options" and "examples" section.
All options are optional and have default values.
1type RestrictedRecord = Record<string, unknown> & { className?: never }; 2 3type TagNameFunction = (type?: string, title?: string) => string; 4type ClassNameFunction = (type?: string, title?: string) => string[]; 5type PropertyFunction = (type?: string, title?: string) => RestrictedRecord; 6type TitleFunction = (type?: string, title?: string) => string | null | undefined; 7 8use(remarkFlexibleContainers, { 9 containerTagName?: string | TagNameFunction; // default is "div" 10 containerClassName?: string | ClassNameFunction; // default is "remark-container" 11 containerProperties?: PropertyFunction; 12 title?: TitleFunction; 13 titleTagName?: string | TagNameFunction; // default is "div" 14 titleClassName?: string | ClassNameFunction; // // default is "remark-container-title" 15 titleProperties?: PropertyFunction; 16} as FlexibleContainerOptions);
containerTagName
It is a string or a callback (type?: string, title?: string) => string
option for providing custom HTML tag name for the container
node.
By default, it is div
.
1use(remarkFlexibleContainers, { 2 containerTagName: "section"; 3});
Now, the container tag names will be section
.
1<section class="..."> 2 <!-- ... --> 3</section>
The option can take also a callback function, which has two optional arguments type
and title
, and returns string representing a custom tag name.
1use(remarkFlexibleContainers, { 2 containerTagName: (type, title) => { 3 return type === "details" ? "details" : "div"; 4 } 5});
Now, the container tag names will be div
or details
. It is a good start for creating details-summary
HTML elements in markdown.
1::: details Title 2<!-- ... --> 3::: 4 5::: warning Title 6<!-- ... --> 7:::
1<details class="..."> 2 <!-- ... --> 3</details> 4<div class="..."> 5 <!-- ... --> 6</div>
containerClassName
It is a string or a callback (type?: string, title?: string) => string[]
option for providing custom class name for the container
node.
By default, it is remark-container
, and all container nodes' classnames will contain remark-container
.
A container node contains also a secondary class name representing the type of the container, like warning
or info
. If there is no type
of the container, then the secondary class name will not present.
1::: danger Title 2<!-- ... --> 3:::
1<div class="remark-container danger"> 2 <!-- ... --> 3</div>
1use(remarkFlexibleContainers, { 2 containerClassName: "custom-container"; 3});
Now, the container nodes will have custom-container
as a className, and the secondary class names will be the type
of the container, if exists.
1::: danger Title 2<!-- ... --> 3:::
1<div class="custom-container danger"> 2 <!-- ... --> 3</div>
The option can take also a callback function, which has two optional arguments type
and title
, and returns array of strings representing class names.
1use(remarkFlexibleContainers, { 2 containerClassName: (type, title) => { 3 return [`remark-container-${type ?? "note"}`] 4 }; 5});
Now, the container class names will contain only one class name like remark-container-warning
, remark-container-note
etc.
1::: 2<!-- ... --> 3:::
1<div class="remark-container-note"> 2 <!-- ... --> 3</div>
[!WARNING] If you use the
containerClassName
option as a callback function, it is your responsibility to define class names, add the type of the container into class names etc. in an array.
containerProperties
It is a callback (type?: string, title?: string) => Record<string, unknown> & { className?: never }
option to set additional properties for the container
node.
The callback function that takes the type
and the title
as optional arguments and returns object which is going to be used for adding additional properties into the container
node.
The className
key is forbidden and effectless in the returned object.
1use(remarkFlexibleContainers, { 2 containerProperties(type, title) { 3 return { 4 ["data-type"]: type, 5 ["data-title"]: title, 6 }; 7 }, 8});
Now, the container nodes which have a type and a title will contain data-type
and data-title
properties.
1::: danger Title 2<!-- ... --> 3:::
1<div class="remark-container danger" data-type="danger" data-title="Title"> 2 <!-- ... --> 3</div>
title
It is a callback (type?: string, title?: string) => string | null | undefined
option to set the title with a callback function.
The remark-flexible-containers
adds a title
node normally if a title is provided in markdown.
1::: danger Title 2<!-- ... --> 3:::
1<div class="remark-container danger"> 2 <div class="remark-container-title">Title</div> 3 <!-- ... --> 4</div>
if the callback function returns null title: () => null
, the plugin will not add the title
node.
1use(remarkFlexibleContainers, { 2 title: () => null, 3});
1<div class="remark-container danger"> 2 <!-- There will be NO title node --> 3 <!-- ... --> 4</div>
The callback function takes the type
and the title
as optional arguments and returns string | null | undefined. For example if there is no title you would want the title is the type of the container as a fallback.
1use(remarkFlexibleContainers, { 2 title: (type, title) => { 3 return title ?? type ? type.charAt(0).toUpperCase() + type.slice(1) : "Fallback Title"; 4 }, 5});
1::: info Title 2<!-- ... --> 3::: 4 5::: info 6<!-- ... --> 7::: 8 9::: 10<!-- ... --> 11:::
1<div class="remark-container info"> 2 <div class="remark-container-title info">Title</div> 3 <!-- ... --> 4</div> 5<div class="remark-container info"> 6 <div class="remark-container-title info">Info</div> 7 <!-- ... --> 8</div> 9<div class="remark-container"> 10 <div class="remark-container-title">Fallback Title</div> 11 <!-- ... --> 12</div>
titleTagName
It is a string or a callback (type?: string, title?: string) => string
option for providing custom HTML tag name for the title
node.
By default, it is div
.
1use(remarkFlexibleContainers, { 2 titleTagName: "span"; 3});
Now, the title tag names will be span
.
1<div class="..."> 2 <span class="...">Title</span> 3 <!-- ... --> 4</div>
The option can take also a callback function, which has two optional arguments type
and title
, and returns string representing a custom tag name.
1use(remarkFlexibleContainers, { 2 containerTagName: (type, title) => { 3 return type === "details" ? "details" : "div"; 4 }, 5 titleTagName: (type, title) => { 6 return type === "details" ? "summary" : "span"; 7 } 8});
Now, the container tag names will be span
or summary
. It is a good complementary for creating details-summary
HTML elements in markdown.
1::: details Title 2<!-- ... --> 3::: 4 5::: warning Title 6<!-- ... --> 7:::
1<details class="..."> 2 <summary class="...">Title</summary> 3 <!-- ... --> 4</details> 5<div class="..."> 6 <span class="...">Title</span> 7 <!-- ... --> 8</div>
titleClassName
It is a string or a callback (type?: string, title?: string) => string[]
option for providing custom class name for the title
node.
By default, it is remark-container-title
, and all title nodes' classnames will contain remark-container-title
.
A title node contains also a secondary class name representing the type of the container, like warning
or info
. If there is no type
of the container, then the secondary class name will not present.
1::: danger Title 2<!-- ... --> 3:::
1<div class="..."> 2 <div class="remark-container-title danger">Title</div> 3 <!-- ... --> 4</div>
1use(remarkFlexibleContainers, { 2 titleClassName: "custom-container-title"; 3});
Now, the title nodes will have custom-container-title
as a className, and the secondary class names will be the type
of the container, if exists.
1::: danger Title 2<!-- ... --> 3:::
1<div class="..."> 2 <div class="custom-container-title danger">Title</div> 3 <!-- ... --> 4</div>
The option can take also a callback function, which has two optional arguments type
and title
, and returns array of strings representing class names.
1use(remarkFlexibleContainers, { 2 titleClassName: (type, title) => { 3 return type ? [`container-title-${type}`] : ["container-title"] 4 }; 5});
Now, the container class names will contain only one class name like container-title-warning
, container-title
etc.
1::: tip Title 2<!-- ... --> 3::: 4 5::: 6<!-- ... --> 7:::
1<div class="..."> 2 <div class="container-title-tip">Title</div> 3 <!-- ... --> 4</div> 5 6<div class="..."> 7 <!-- No title node because there is no title in the second container 8 and no fallback title with `title` option --> 9 <!-- ... --> 10</div>
[!WARNING] If you use the
titleClassName
option as a callback function, it is your responsibility to define class names, add the type of the container into class names etc. in an array.
titleProperties
It is a callback (type?: string, title?: string) => Record<string, unknown> & { className?: never }
option to set additional properties for the title
node.
The callback function that takes the type
and the title
as optional arguments and returns object which is going to be used for adding additional properties into the title
node.
The className
key is forbidden and effectless in the returned object.
1use(remarkFlexibleContainers, { 2 titleProperties(type, title) { 3 return { 4 ["data-type"]: type, 5 }; 6 }, 7});
Now, the title nodes which have a type will contain data-type
property.
1::: danger Title 2<!-- ... --> 3:::
1<div class="..."> 2 <div class="..." data-type="danger">Title</div> 3 <!-- ... --> 4</div>
1::: info The Title of Information 2Some information 3:::
1use(remarkFlexibleContainers);
is going to produce as default:
1<div class="remark-container info"> 2 <div class="remark-container-title info">The Title of Information</div> 3 <p>Some information</p> 4</div>
() => null
1use(remarkFlexibleContainers, { 2 title: () => null, 3});
is going to produce the container without title node (even if the the title is provided in markdown):
1<div class="remark-container info"> 2 <p>Some information</p> 3</div>
1use(remarkFlexibleContainers, { 2 containerTagName: "section", 3 containerClassName: "remark-custom-wrapper", 4 containerProperties(type, title) { 5 return { 6 ["data-type"]: type, 7 ["data-title"]: title, 8 }; 9 }, 10 title: (type, title) => title ? title.toUpperCase() : "Fallback Title"; 11 titleTagName: "span", 12 titleClassName: "remark-custom-wrapper-title", 13 titleProperties: (type, title) => { 14 ["data-type"]: type, 15 }, 16});
is going to produce the container section
element like below:
1<section class="remark-custom-wrapper info" data-type="info" data-title="The Title of Information"> 2 <span class="remark-custom-wrapper-title info" data-type="info">THE TITLE OF INFORMATION</span> 3 <p>Some information</p> 4</section>
1use(remarkFlexibleContainers, { 2 containerTagName(type) { 3 return type === "details" ? "details" : "div"; 4 }, 5 containerClassName(type) { 6 return type === "details" ? ["remark-details"] : ["remark-container", type ?? ""]; 7 }, 8 titleTagName(type) { 9 return type === "details" ? "summary" : "span"; 10 }, 11 titleClassName(type) { 12 return type === "details" ? ["remark-summary"] : ["remark-container-title", type ?? ""]; 13 }, 14});
With above options you can create details-summary
HTML element in addition to containers easily if you provide the type of the container as details
.
1::: details Title 2Some information 3::: 4 5::: warning Title 6Some information 7:::
1<details class="remark-details"> 2 <summary class="remark-summary">Title</summary> 3 <p>Some information</p> 4</details> 5<div class="remark-container warning"> 6 <span class="remark-container warning">Title</span> 7 <p>Some information</p> 8</div>
You can use the plugin syntax without providing a type and a title.
1::: 2Some information 3:::
It will not add a title
node since it is not provided (assume that title
option is not provided for a fallback title, as well), and it will also not add the type as a classname into the container:
1<div class="remark-container"> 2 <p>Some information</p> 3</div>
The flexible container can contain also HTML elements and MDX components:
1::: tip Title
2This package is so _**cool** and **flexible**_
3
4::it does not confuse with double colons::
5
6==marked text via plugin `remark-flexible-markers`==
7<mark>marked text via HTML element in markdown</mark>
8<MarkRed>marked text via custom marker in support of MDX</MarkRed>
9
10<details>
11 <summary>HTML tag works too</summary>
12 <p>I am working</p>
13</details>
14
15other paragraph *italic content* and,
16some **bold content** without stress
17:::
As of version ^1.2.0
, the remark-flexible-containers
supports syntax for specific identifiers (tagname
, id
, classnames
) for individual container
and title
node. For example:
1::: info {section#foo.myclass} Title Of Information {span#baz.someclass} 2<!-- content --> 3:::
1<section class="remark-container info myclass" id="foo"> 2 <span class="remark-container-title info someclass" id="baz"> 3 Title Of Information 4 </span> 5 <!-- content --> 6</section>
The identifiers (tagname
, id
, classnames
) must be inside curly braces.
Syntax is very simple.
tagname
is to be compatible HTML tag name, and may present only once,id
is to start with hash #
, and may present only once,classnames
are to start with dot .
, and may present many.There are two groups of identifiers. Each group is optional, may present or not.
The first group of identifiers (just after the type
) is for container
node.
The second group of identifiers (just after the title
) is for title
node.
Here are some example usages. For simplicity, I omitted the container contents and ending syntax, just put the beginning syntax in the examples. All are valid usage for specific identifiers.
[!TIP] These identifiers can be placed as all three, any two, or just any of them in the desired order, with or without a space between them. This is why the "flexibility" term comes from.
1::: info {section#foo.myclass.second-class} Title {span#baz.someclass.other-class} 2::: info {section#foo.myclass} Title {span#baz.someclass} 3::: info {section #foo .myclass .second-class} Title {span #baz .someclass .other-class} 4::: info {section #foo .myclass} Title {span #baz .someclass} 5::: info {section.myclass#foo} Title {span.someclass#baz} 6::: info {.myclass#foo} Title {.someclass#baz} 7::: info {.myclass #foo} Title {.someclass #baz} 8::: info {.myclass #foo section} Title {.someclass #baz span} 9::: info {#foo section} Title {#baz span} 10::: info {.myclass} Title {#baz} 11::: info {#foo} Title {.someclass} 12::: info {#foo} Title 13::: info {#foo} 14::: info {section#foo.myclass} 15::: info Title {.someclass} 16::: info Title {span#baz.someclass}
You should consider that specific identifiers for title
breaks the option title: () => null
, and the title will take place for that individual container.
This plugin only modifies the mdast (markdown abstract syntax tree) as explained.
This package is fully typed with TypeScript. The plugin options' type is exported as FlexibleContainerOptions
.
This plugin works with unified
version 6+ and remark
version 7+. It is compatible with mdx
version 2+.
Use of remark-flexible-containers
does not involve rehype (hast) or user content so there are no openings for 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
elementrehype-highlight-code-lines
– Rehype plugin to add line numbers to code blocks and allow highlighting of desired code linesrehype-code-meta
– Rehype plugin to copy code.data.meta
to code.properties.metastring
rehype-image-toolkit
– Rehype plugin to enhance Markdown image syntax ![]()
and Markdown/MDX media elements (<img>
, <audio>
, <video>
) by auto-linking bracketed or parenthesized image URLs, wrapping them in <figure>
with optional captions, unwrapping images/videos/audio from paragraph, parsing directives in title for styling and adding attributes, and dynamically converting images into <video>
or <audio>
elements based on file extension.recma-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.recma-mdx-change-imports
– Recma plugin to convert import declarations for assets and media with relative links into variable declarations with string URLs, enabling direct asset URL resolution in compiled MDX.recma-mdx-import-media
– Recma plugin to turn media relative paths into import declarations for both markdown and html syntax in MDX.recma-mdx-import-react
– Recma plugin to ensure getting React
instance from the arguments and to make the runtime props {React, jsx, jsxs, jsxDev, Fragment}
is available in the dynamically imported components in the compiled source of MDX.recma-mdx-html-override
– Recma plugin to allow selected raw HTML elements to be overridden via MDX components.recma-mdx-interpolate
– Recma plugin to enable interpolation of identifiers wrapped in curly braces within the alt
, src
, href
, and title
attributes of markdown link and image syntax in MDX.MIT License © ipikuka
No vulnerabilities found.
No security vulnerabilities found.