Admonitions #1323
SuperRonanCraft
started this conversation in
Docs Feedback
Admonitions
#1323
Replies: 1 comment
-
That was likely a bug, some types from Docusaurus are not included, you can do: import { remarkAdmonition } from 'fumadocs-core/mdx-plugins';
export default defineConfig({
mdxOptions: {
remarkPlugins: [[remarkAdmonition, { types: ['warn', 'info', 'error', 'tip', 'danger', 'warning'] }]],
}
}) Or clone the remark plugin (fix will available on v15) import { type Transformer } from 'unified';
import { visit } from 'unist-util-visit';
import { type Root, type RootContent } from 'mdast';
import { flattenNode } from '@/mdx-plugins/remark-utils';
export interface RemarkAdmonitionOptions {
tag?: string;
/**
* Map type to another type
*/
typeMap?: Record<string, string>;
}
/**
* Remark Plugin to support Admonition syntax
*
* Useful when Migrating from Docusaurus
*/
export function remarkAdmonition(
options: RemarkAdmonitionOptions = {},
): Transformer<Root, Root> {
const tag = options.tag ?? ':::';
// compatible with Docusaurus
const typeMap = options.typeMap ?? {
info: 'info',
warn: 'warn',
note: 'info',
tip: 'info',
warning: 'warn',
danger: 'error',
};
function replaceNodes(nodes: RootContent[]) {
if (nodes.length === 0) return;
let open = -1;
let attributes = [];
// if children contain nested admonitions
let hasIntercept = false;
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].type !== 'paragraph') continue;
const text = flattenNode(nodes[i]);
const typeName = Object.keys(typeMap).find((type) =>
text.startsWith(`${tag}${type}`),
);
if (typeName) {
if (open !== -1) {
hasIntercept = true;
continue;
}
open = i;
attributes.push({
type: 'mdxJsxAttribute',
name: 'type',
value: typeMap[typeName],
});
const meta = text.slice(`${tag}${typeName}`.length);
if (meta.startsWith('[') && meta.endsWith(']')) {
attributes.push({
type: 'mdxJsxAttribute',
name: 'title',
value: meta.slice(1, -1),
});
}
}
if (open !== -1 && text === tag) {
const children = nodes.slice(open + 1, i);
nodes.splice(open, i - open + 1, {
type: 'mdxJsxFlowElement',
name: 'Callout',
attributes,
children: hasIntercept ? replaceNodes(children) : children,
} as RootContent);
open = -1;
hasIntercept = false;
attributes = [];
i = open;
}
}
}
return (tree) => {
visit(tree, (node) => {
if (!('children' in node)) return;
replaceNodes(node.children);
});
};
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wanted to ask about Admonitions to spice up my markdown formatting
I installed the Remark Admonition plugin, but its only listening to the
:::warning:::
admonition and nothing else, its also formatted super weird.I do want to add, I had to guess where to install the remark plugin, it doesn't say what file to edit nor that I had to put remarkPlugins inside the defineConfig from fumadocs-mdx/config object.
Heres the docs link I followed: https://fumadocs.vercel.app/docs/headless/mdx/remark-admonition
![image](https://private-user-images.githubusercontent.com/7385626/406797053-f60293c8-9794-4d23-9220-a93cb6f9a9bf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Mzg3NTIsIm5iZiI6MTczOTYzODQ1MiwicGF0aCI6Ii83Mzg1NjI2LzQwNjc5NzA1My1mNjAyOTNjOC05Nzk0LTRkMjMtOTIyMC1hOTNjYjZmOWE5YmYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMTY1NDEyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjFkMGY3NzU3ZDAyMzUyMWUzMDBjNDEyYzliOTIxMDE4M2VlOTc5NTg0M2EwNWMyNTM2MzNlZmM2MWI3Y2NjYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.G_Dqksxk6gfpuUtdpcllMiaxbc1BUkDKDqmFG5ioqu4)
![image](https://private-user-images.githubusercontent.com/7385626/406797129-3f5d6a97-a8d2-435a-a8d8-19c761ce16c7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Mzg3NTIsIm5iZiI6MTczOTYzODQ1MiwicGF0aCI6Ii83Mzg1NjI2LzQwNjc5NzEyOS0zZjVkNmE5Ny1hOGQyLTQzNWEtYThkOC0xOWM3NjFjZTE2YzcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMTY1NDEyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTE5MWQ4YTg5YzgyZDFmYmMyZjBiZmM4OWJkOGQ0MjRjOWFjMzk2ODU5MjIzYjZhMWE1OThmOTlhZmUwZDE3NyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.BU2iJZSkJI3mIkvvAr85t-rHfTCT00rIUqAd5hoiZQc)
My souce.config.ts file:
And the warning admonition:
Vs any other non-warning admonition:
![image](https://private-user-images.githubusercontent.com/7385626/406797176-8ba1dd6b-7ef4-473e-a653-42312c7bb3b5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Mzg3NTIsIm5iZiI6MTczOTYzODQ1MiwicGF0aCI6Ii83Mzg1NjI2LzQwNjc5NzE3Ni04YmExZGQ2Yi03ZWY0LTQ3M2UtYTY1My00MjMxMmM3YmIzYjUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMTY1NDEyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZGI0ODFhNDYyOTFjZTA1NTQ0YTQ5ZWJhMTg2ZWVkZTYyYjljZGEzN2JkOGIyZGY1OWIzMjg4ZGYyZWZlMmI4MSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.1o7uN6ZY82nWvOaNoZTiXsBImcfwP4R4zelGAP3QMqM)
From what I heard, they should look like this:
![image](https://private-user-images.githubusercontent.com/7385626/406797228-fdb9477c-54fd-4fba-8cdc-7c3801b423bd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Mzg3NTIsIm5iZiI6MTczOTYzODQ1MiwicGF0aCI6Ii83Mzg1NjI2LzQwNjc5NzIyOC1mZGI5NDc3Yy01NGZkLTRmYmEtOGNkYy03YzM4MDFiNDIzYmQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMTY1NDEyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YWZkMDEwZTk0MThkNGQxOGNiMmEzYTllZmE0OWMwZmQ4YWM0NWUwMDAwMDcwNDcwZDY0NzMwNDVjZjcyNDY0MCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.Zl_7-vXJCLpwaWPuBbc0-io6SMT1wQii9puxp0eviYQ)
Beta Was this translation helpful? Give feedback.
All reactions