File tree Expand file tree Collapse file tree 6 files changed +25
-8
lines changed Expand file tree Collapse file tree 6 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ export async function getCode(file: string, config = {}) {
36
36
remarkCodeHike ,
37
37
{
38
38
autoImport : false ,
39
+ skipLanguages : [ "" , "mermaid" ] ,
39
40
showCopyButton : true ,
40
41
theme,
41
42
...config ,
Original file line number Diff line number Diff line change @@ -12,11 +12,18 @@ import { mergeFocus } from "../utils"
12
12
import { CodeNode , SuperNode } from "./nodes"
13
13
import { CodeHikeConfig } from "./config"
14
14
15
- export function isEditorNode ( node : SuperNode ) {
15
+ export function isEditorNode (
16
+ node : SuperNode ,
17
+ config : CodeHikeConfig
18
+ ) {
19
+ if ( node . type === "code" ) {
20
+ const lang = ( node . lang as string ) || ""
21
+ const shouldSkip = config . skipLanguages . includes ( lang )
22
+ return ! shouldSkip
23
+ }
16
24
return (
17
- node . type === "code" ||
18
- ( node . type === "mdxJsxFlowElement" &&
19
- node . name === "CH.Code" )
25
+ node . type === "mdxJsxFlowElement" &&
26
+ node . name === "CH.Code"
20
27
)
21
28
}
22
29
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ export type CodeHikeConfig = {
2
2
theme : any
3
3
lineNumbers ?: boolean
4
4
autoImport ?: boolean
5
+ skipLanguages : string [ ]
5
6
showExpandButton ?: boolean
6
7
showCopyButton ?: boolean
7
8
}
@@ -17,5 +18,6 @@ export function addConfigDefaults(
17
18
...config ,
18
19
theme : config ?. theme || { } ,
19
20
autoImport : config ?. autoImport === false ? false : true ,
21
+ skipLanguages : config ?. skipLanguages || [ ] ,
20
22
}
21
23
}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export async function extractStepsInfo(
29
29
30
30
steps [ stepIndex ] = steps [ stepIndex ] || { children : [ ] }
31
31
const step = steps [ stepIndex ]
32
- if ( ! step . editorStep && isEditorNode ( child ) ) {
32
+ if ( ! step . editorStep && isEditorNode ( child , config ) ) {
33
33
const editorStep = await mapAnyCodeNode (
34
34
{ node : child , parent, index : i } ,
35
35
config
Original file line number Diff line number Diff line change 1
1
import { NodeInfo , toJSX , visitAsync } from "./unist-utils"
2
- import { mapAnyCodeNode , mapEditor } from "./code"
2
+ import {
3
+ isEditorNode ,
4
+ mapAnyCodeNode ,
5
+ mapEditor ,
6
+ } from "./code"
3
7
import { CodeNode , JsxNode , SuperNode } from "./nodes"
4
8
import { CodeHikeConfig } from "./config"
5
9
@@ -20,7 +24,10 @@ export async function transformCodes(
20
24
tree ,
21
25
"code" ,
22
26
async ( node : CodeNode , index , parent ) => {
23
- await transformCode ( { node, index, parent } , config )
27
+ // here we check if we should skip it because of the language:
28
+ if ( isEditorNode ( node , config ) ) {
29
+ await transformCode ( { node, index, parent } , config )
30
+ }
24
31
}
25
32
)
26
33
}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ async function transformSection(
27
27
node ,
28
28
[ "mdxJsxFlowElement" , "code" ] ,
29
29
async ( editorNode , index , parent ) => {
30
- if ( isEditorNode ( editorNode ) ) {
30
+ if ( isEditorNode ( editorNode , config ) ) {
31
31
props = await mapAnyCodeNode (
32
32
{ node : editorNode , index, parent } ,
33
33
config
You can’t perform that action at this time.
0 commit comments