File tree 3 files changed +32
-2
lines changed
3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 1
1
const fs = require ( 'fs' ) ;
2
2
const path = require ( 'path' ) ;
3
- const indentedCodeBlock = require ( './codemods/indentedCodeBlock' ) ;
4
3
5
4
const siteUrl = 'https://docs.newrelic.com' ;
6
5
@@ -181,7 +180,7 @@ module.exports = {
181
180
// https://github.com/mdx-js/mdx/issues/1283
182
181
//
183
182
// If this is addressed in MDX v2, we can safely remove this.
184
- remarkPlugins : [ indentedCodeBlock ] ,
183
+ remarkPlugins : [ ] ,
185
184
gatsbyRemarkPlugins : [
186
185
{
187
186
resolve : 'gatsby-remark-images' ,
@@ -217,6 +216,11 @@ module.exports = {
217
216
maxWidth : 1200 ,
218
217
} ,
219
218
} ,
219
+ {
220
+ resolve : require . resolve (
221
+ './plugins/gatsby-remark-mdx-v2-fenced-code-blocks'
222
+ ) ,
223
+ } ,
220
224
] ,
221
225
} ,
222
226
} ,
Original file line number Diff line number Diff line change
1
+ const { createCompiler } = require ( '@mdx-js/mdx' ) ;
2
+ const visit = require ( 'unist-util-visit' ) ;
3
+
4
+ const INVALID_CODE_BLOCK = / ` { 3 , } \n / ;
5
+
6
+ const compiler = createCompiler ( ) ;
7
+
8
+ module . exports = ( { markdownAST } ) => {
9
+ visit (
10
+ markdownAST ,
11
+ ( node ) => node . type === 'code' && INVALID_CODE_BLOCK . test ( node . value ) ,
12
+ ( node , idx , parent ) => {
13
+ const idxOfCode = node . value . indexOf ( '```' ) ;
14
+ const text = node . value . slice ( 0 , idxOfCode ) ;
15
+ const parsed = compiler . parse (
16
+ node . value . slice ( idxOfCode ) . replace ( / ^ ` + / , '' )
17
+ ) ;
18
+
19
+ node . value = text . trim ( ) ;
20
+ parent . children . splice ( idx + 1 , 0 , ...parsed . children ) ;
21
+ }
22
+ ) ;
23
+
24
+ return markdownAST ;
25
+ } ;
Original file line number Diff line number Diff line change
1
+ {}
You can’t perform that action at this time.
0 commit comments