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 = {}) {
3636 remarkCodeHike ,
3737 {
3838 autoImport : false ,
39+ skipLanguages : [ "" , "mermaid" ] ,
3940 showCopyButton : true ,
4041 theme,
4142 ...config ,
Original file line number Diff line number Diff line change @@ -12,11 +12,18 @@ import { mergeFocus } from "../utils"
1212import { CodeNode , SuperNode } from "./nodes"
1313import { CodeHikeConfig } from "./config"
1414
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+ }
1624 return (
17- node . type === "code" ||
18- ( node . type === "mdxJsxFlowElement" &&
19- node . name === "CH.Code" )
25+ node . type === "mdxJsxFlowElement" &&
26+ node . name === "CH.Code"
2027 )
2128}
2229
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ export type CodeHikeConfig = {
22 theme : any
33 lineNumbers ?: boolean
44 autoImport ?: boolean
5+ skipLanguages : string [ ]
56 showExpandButton ?: boolean
67 showCopyButton ?: boolean
78}
@@ -17,5 +18,6 @@ export function addConfigDefaults(
1718 ...config ,
1819 theme : config ?. theme || { } ,
1920 autoImport : config ?. autoImport === false ? false : true ,
21+ skipLanguages : config ?. skipLanguages || [ ] ,
2022 }
2123}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export async function extractStepsInfo(
2929
3030 steps [ stepIndex ] = steps [ stepIndex ] || { children : [ ] }
3131 const step = steps [ stepIndex ]
32- if ( ! step . editorStep && isEditorNode ( child ) ) {
32+ if ( ! step . editorStep && isEditorNode ( child , config ) ) {
3333 const editorStep = await mapAnyCodeNode (
3434 { node : child , parent, index : i } ,
3535 config
Original file line number Diff line number Diff line change 11import { NodeInfo , toJSX , visitAsync } from "./unist-utils"
2- import { mapAnyCodeNode , mapEditor } from "./code"
2+ import {
3+ isEditorNode ,
4+ mapAnyCodeNode ,
5+ mapEditor ,
6+ } from "./code"
37import { CodeNode , JsxNode , SuperNode } from "./nodes"
48import { CodeHikeConfig } from "./config"
59
@@ -20,7 +24,10 @@ export async function transformCodes(
2024 tree ,
2125 "code" ,
2226 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+ }
2431 }
2532 )
2633}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ async function transformSection(
2727 node ,
2828 [ "mdxJsxFlowElement" , "code" ] ,
2929 async ( editorNode , index , parent ) => {
30- if ( isEditorNode ( editorNode ) ) {
30+ if ( isEditorNode ( editorNode , config ) ) {
3131 props = await mapAnyCodeNode (
3232 { node : editorNode , index, parent } ,
3333 config
You can’t perform that action at this time.
0 commit comments