@@ -4,6 +4,7 @@ import { wrapChildren } from "./to-estree"
44import { annotationsMap } from "../mdx-client/annotations"
55import { JsxNode as JsxNode , SuperNode } from "./nodes"
66import { getCommentData } from "./comment-data"
7+ import { CodeHikeConfig } from "./config"
78
89export function getAnnotationsFromMetastring (
910 options : Record < string , string >
@@ -18,7 +19,10 @@ export function getAnnotationsFromMetastring(
1819 return annotations
1920}
2021
21- export function extractAnnotationsFromCode ( code : Code ) {
22+ export function extractAnnotationsFromCode (
23+ code : Code ,
24+ config : CodeHikeConfig
25+ ) {
2226 const { lines } = code
2327 let lineNumber = 1
2428 const annotations = [ ] as CodeAnnotation [ ]
@@ -52,24 +56,26 @@ export function extractAnnotationsFromCode(code: Code) {
5256 }
5357
5458 // 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 ( "" )
6166
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+ } )
7076 } )
71- } )
72- lineNumber ++
77+ lineNumber ++
78+ }
7379 }
7480 return [ annotations , focusList . join ( "," ) ] as const
7581}
0 commit comments