@@ -18,12 +18,7 @@ import {
18
18
DEFAULT_THEMES ,
19
19
DEFAULT_LANGS ,
20
20
} from './shiki-constants.js' ;
21
- import {
22
- getLanguage ,
23
- getLinesToHighlight ,
24
- lineHighlightPattern ,
25
- LINE_HIGHLIGHT_CLASS ,
26
- } from './utils.js' ;
21
+ import { getLanguage } from './utils.js' ;
27
22
28
23
export type RehypeSyntaxHighlightingOptions = {
29
24
theme ?: ShikiTheme ;
@@ -118,8 +113,6 @@ const traverseNode = (
118
113
) => {
119
114
try {
120
115
const code = toString ( node ) ;
121
- const lines = code . split ( '\n' ) ;
122
- let linesToHighlight = getLinesToHighlight ( node , lines . length ) ;
123
116
124
117
const hast = highlighter . codeToHast ( code , {
125
118
lang : lang ?? DEFAULT_LANG ,
@@ -139,36 +132,11 @@ const traverseNode = (
139
132
if ( ! codeElement ) return ;
140
133
141
134
let lineNumber = 0 ;
142
- visit ( codeElement , 'element' , ( span , spanIndex , spanParent ) => {
143
- if (
144
- ! spanParent ||
145
- spanParent . type !== 'element' ||
146
- spanParent . tagName !== 'code' ||
147
- span . tagName !== 'span' ||
148
- ( ! span . children . length && spanIndex === spanParent . children . length - 1 ) ||
149
- ( typeof span . properties . class !== 'string' && ! Array . isArray ( span . properties . class ) ) ||
150
- ! span . properties . class . includes ( 'line' )
151
- ) {
152
- return ;
153
- }
154
-
155
- lineNumber ++ ;
156
- if ( linesToHighlight . includes ( lineNumber ) ) {
157
- if ( typeof span . properties . class === 'string' ) {
158
- span . properties . class += ' ' + LINE_HIGHLIGHT_CLASS ;
159
- } else {
160
- span . properties . class = [ ...span . properties . class , LINE_HIGHLIGHT_CLASS ] ;
161
- }
162
- }
163
- } ) ;
164
135
165
136
const preChild = codeElement . children [ 0 ] as Element ;
166
137
const numberOfLines = lineNumber ;
167
138
168
139
node . data = node . data ?? { } ;
169
- if ( node . data . meta ) {
170
- node . data . meta = node . data . meta . replace ( lineHighlightPattern , '' ) . trim ( ) ;
171
- }
172
140
codeElement . data = node . data ;
173
141
codeElement . properties . numberOfLines = numberOfLines ;
174
142
if ( preChild ) {
0 commit comments