@@ -4,6 +4,7 @@ import { wrapChildren } from "./to-estree"
4
4
import { annotationsMap } from "../mdx-client/annotations"
5
5
import { JsxNode as JsxNode , SuperNode } from "./nodes"
6
6
import { getCommentData } from "./comment-data"
7
+ import { CodeHikeConfig } from "./config"
7
8
8
9
export function getAnnotationsFromMetastring (
9
10
options : Record < string , string >
@@ -18,7 +19,10 @@ export function getAnnotationsFromMetastring(
18
19
return annotations
19
20
}
20
21
21
- export function extractAnnotationsFromCode ( code : Code ) {
22
+ export function extractAnnotationsFromCode (
23
+ code : Code ,
24
+ config : CodeHikeConfig
25
+ ) {
22
26
const { lines } = code
23
27
let lineNumber = 1
24
28
const annotations = [ ] as CodeAnnotation [ ]
@@ -52,24 +56,26 @@ export function extractAnnotationsFromCode(code: Code) {
52
56
}
53
57
54
58
// extract links
55
- lineNumber = 1
56
- while ( lineNumber <= lines . length ) {
57
- const line = lines [ lineNumber - 1 ]
58
- const lineContent = line . tokens
59
- . map ( t => t . content )
60
- . join ( "" )
59
+ if ( config . autoLink ) {
60
+ lineNumber = 1
61
+ while ( lineNumber <= lines . length ) {
62
+ const line = lines [ lineNumber - 1 ]
63
+ const lineContent = line . tokens
64
+ . map ( t => t . content )
65
+ . join ( "" )
61
66
62
- const urls = extractURLsFromLine ( lineContent )
63
- urls . forEach ( ( { url, start, end } ) => {
64
- const Component = annotationsMap [ "link" ]
65
- const focus = `${ lineNumber } [${ start + 1 } :${ end } ]`
66
- annotations . push ( {
67
- Component,
68
- focus,
69
- data : url ,
67
+ const urls = extractURLsFromLine ( lineContent )
68
+ urls . forEach ( ( { url, start, end } ) => {
69
+ const Component = annotationsMap [ "link" ]
70
+ const focus = `${ lineNumber } [${ start + 1 } :${ end } ]`
71
+ annotations . push ( {
72
+ Component,
73
+ focus,
74
+ data : url ,
75
+ } )
70
76
} )
71
- } )
72
- lineNumber ++
77
+ lineNumber ++
78
+ }
73
79
}
74
80
return [ annotations , focusList . join ( "," ) ] as const
75
81
}
0 commit comments