File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 11import fs from "fs"
22import { remarkCodeHike } from "../src/index"
33import { compile } from "@mdx-js/mdx"
4- import theme from "shiki/themes/nord .json"
4+ import theme from "shiki/themes/rose-pine-moon .json"
55import { withDebugger } from "mdx-debugger"
66
77export async function getFiles ( ) {
Original file line number Diff line number Diff line change @@ -28,11 +28,25 @@ export function getCommentData(
2828 }
2929}
3030
31+ function getTextAfter (
32+ line : Code [ "lines" ] [ 0 ] ,
33+ prefix : string
34+ ) {
35+ const firstIndex = line . tokens . findIndex ( t =>
36+ t . content . trim ( ) . startsWith ( prefix )
37+ )
38+ if ( firstIndex === - 1 ) {
39+ return undefined
40+ }
41+ return line . tokens
42+ . slice ( firstIndex )
43+ . map ( t => t . content )
44+ . join ( "" )
45+ }
46+
3147const commentRegex = / \/ \/ \s + ( \w + ) ( \S * ) \s * ( .* ) /
3248function otherComment ( line : Code [ "lines" ] [ 0 ] ) {
33- const comment = line . tokens . find ( t =>
34- t . content . trim ( ) . startsWith ( "//" )
35- ) ?. content
49+ const comment = getTextAfter ( line , "//" )
3650
3751 if ( ! comment ) {
3852 return [ ]
@@ -56,9 +70,7 @@ const bashLikeLangs = [
5670]
5771const bashLikeCommentRegex = / # \s + ( \w + ) ( \S * ) \s * ( .* ) /
5872function bashLikeComment ( line : Code [ "lines" ] [ 0 ] ) {
59- const comment = line . tokens . find ( t =>
60- t . content . trim ( ) . startsWith ( "#" )
61- ) ?. content
73+ const comment = getTextAfter ( line , "#" )
6274
6375 if ( ! comment ) {
6476 return [ ]
You can’t perform that action at this time.
0 commit comments