@@ -8,6 +8,11 @@ import type { RemarkFeedbackBlockOptions } from 'fumadocs-core/mdx-plugins';
88import type { RemarkAutoTypeTableOptions } from 'fumadocs-typescript' ;
99import { shikiConfig } from './lib/shiki' ;
1010import { metaSchema , pageSchema } from 'fumadocs-core/source/schema' ;
11+ import { visit } from 'unist-util-visit' ;
12+ import type { Transformer } from 'unified' ;
13+ import type { Root } from 'mdast' ;
14+
15+ const isLint = process . env . LINT === '1' ;
1116
1217export const docs = defineDocs ( {
1318 docs : {
@@ -22,6 +27,7 @@ export const docs = defineDocs({
2227 postprocess : {
2328 includeProcessedMarkdown : true ,
2429 extractLinkReferences : true ,
30+ valueToExport : [ 'elementIds' ] ,
2531 } ,
2632 async : true ,
2733 async mdxOptions ( environment ) {
@@ -56,21 +62,23 @@ export const docs = defineDocs({
5662 remarkStructureOptions : {
5763 types : [ ...remarkStructureDefaultOptions . types , 'code' ] ,
5864 } ,
59- rehypeCodeOptions : {
60- langs : [ 'ts' , 'js' , 'html' , 'tsx' , 'mdx' ] ,
61- inline : 'tailing-curly-colon' ,
62- themes : {
63- light : 'catppuccin-latte' ,
64- dark : 'catppuccin-mocha' ,
65- } ,
66- transformers : [
67- ...( rehypeCodeDefaultOptions . transformers ?? [ ] ) ,
68- transformerTwoslash ( {
69- typesCache : createFileSystemTypesCache ( ) ,
70- } ) ,
71- transformerEscape ( ) ,
72- ] ,
73- } ,
65+ rehypeCodeOptions : isLint
66+ ? false
67+ : {
68+ langs : [ 'ts' , 'js' , 'html' , 'tsx' , 'mdx' ] ,
69+ inline : 'tailing-curly-colon' ,
70+ themes : {
71+ light : 'catppuccin-latte' ,
72+ dark : 'catppuccin-mocha' ,
73+ } ,
74+ transformers : [
75+ ...( rehypeCodeDefaultOptions . transformers ?? [ ] ) ,
76+ transformerTwoslash ( {
77+ typesCache : createFileSystemTypesCache ( ) ,
78+ } ) ,
79+ transformerEscape ( ) ,
80+ ] ,
81+ } ,
7482 remarkCodeTabOptions : {
7583 parseMdx : true ,
7684 } ,
@@ -79,13 +87,15 @@ export const docs = defineDocs({
7987 id : 'package-manager' ,
8088 } ,
8189 } ,
82- remarkPlugins : [
83- remarkSteps ,
84- remarkMath ,
85- [ remarkFeedbackBlock , feedbackOptions ] ,
86- [ remarkAutoTypeTable , typeTableOptions ] ,
87- remarkTypeScriptToJavaScript ,
88- ] ,
90+ remarkPlugins : isLint
91+ ? [ remarkElementIds ]
92+ : [
93+ remarkSteps ,
94+ remarkMath ,
95+ [ remarkFeedbackBlock , feedbackOptions ] ,
96+ [ remarkAutoTypeTable , typeTableOptions ] ,
97+ remarkTypeScriptToJavaScript ,
98+ ] ,
8999 rehypePlugins : ( v ) => [ rehypeKatex , ...v ] ,
90100 } ) ( environment ) ;
91101 } ,
@@ -110,14 +120,16 @@ export const blog = defineCollections({
110120 const { remarkSteps } = await import ( 'fumadocs-core/mdx-plugins/remark-steps' ) ;
111121
112122 return applyMdxPreset ( {
113- rehypeCodeOptions : {
114- inline : 'tailing-curly-colon' ,
115- themes : {
116- light : 'catppuccin-latte' ,
117- dark : 'catppuccin-mocha' ,
118- } ,
119- transformers : [ ...( rehypeCodeDefaultOptions . transformers ?? [ ] ) , transformerEscape ( ) ] ,
120- } ,
123+ rehypeCodeOptions : isLint
124+ ? false
125+ : {
126+ inline : 'tailing-curly-colon' ,
127+ themes : {
128+ light : 'catppuccin-latte' ,
129+ dark : 'catppuccin-mocha' ,
130+ } ,
131+ transformers : [ ...( rehypeCodeDefaultOptions . transformers ?? [ ] ) , transformerEscape ( ) ] ,
132+ } ,
121133 remarkCodeTabOptions : {
122134 parseMdx : true ,
123135 } ,
@@ -126,7 +138,7 @@ export const blog = defineCollections({
126138 id : 'package-manager' ,
127139 } ,
128140 } ,
129- remarkPlugins : [ remarkSteps ] ,
141+ remarkPlugins : isLint ? [ remarkElementIds ] : [ remarkSteps ] ,
130142 } ) ( environment ) ;
131143 } ,
132144} ) ;
@@ -151,6 +163,25 @@ function transformerEscape(): ShikiTransformer {
151163 } ;
152164}
153165
166+ function remarkElementIds ( ) : Transformer < Root , Root > {
167+ return ( tree , file ) => {
168+ file . data ??= { } ;
169+ file . data . elementIds ??= [ ] ;
170+
171+ visit ( tree , 'mdxJsxFlowElement' , ( element ) => {
172+ if ( ! element . name || ! element . attributes ) return ;
173+
174+ const idAttr = element . attributes . find (
175+ ( attr ) => attr . type === 'mdxJsxAttribute' && attr . name === 'id' ,
176+ ) ;
177+
178+ if ( idAttr && typeof idAttr . value === 'string' ) {
179+ ( file . data . elementIds as string [ ] ) . push ( idAttr . value ) ;
180+ }
181+ } ) ;
182+ } ;
183+ }
184+
154185export default defineConfig ( {
155186 plugins : [
156187 jsonSchema ( {
0 commit comments