File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ { /* prettier-ignore */ }
2
+ ``` py
3
+ import requests
4
+
5
+ # URL: https://api.example.com/data
6
+ # Invalid URL: http://invalid_domain.123
7
+ urls = [" https://typicode.com/todos/1" , " https://typicode.com/todos/2" ]
8
+ responses = [requests.get(url) for url in urls]
9
+ ```
10
+
11
+ ``` ruby mark=3:5
12
+ require ' net/http'
13
+
14
+ url = URI .parse(' https://www.ruby-lang.org/en/' )
15
+ url = URI .parse ' https://www.ruby-lang.org/en/'
16
+ url = URI .parse ' https://www.ruby-lang.org/en/' asdasd;
17
+ response = Net ::HTTP .get_response(url)
18
+ puts response.body
19
+ ```
Original file line number Diff line number Diff line change @@ -50,9 +50,46 @@ export function extractAnnotationsFromCode(code: Code) {
50
50
lineNumber ++
51
51
}
52
52
}
53
+
54
+ // 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 ( "" )
61
+
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 ,
70
+ } )
71
+ } )
72
+ lineNumber ++
73
+ }
53
74
return [ annotations , focusList . join ( "," ) ] as const
54
75
}
55
76
77
+ const urlRegex = / h t t p s ? : \/ \/ [ \w \- _ . ~ : / ? # [ \] @ ! $ & * + , ; = % ] + / g
78
+ function extractURLsFromLine ( line : string ) {
79
+ const urls = [ ]
80
+ let match : RegExpExecArray | null
81
+
82
+ while ( ( match = urlRegex . exec ( line ) ) !== null ) {
83
+ const url = match [ 0 ]
84
+ const start = match . index
85
+ const end = start + url . length
86
+
87
+ urls . push ( { url, start, end } )
88
+ }
89
+
90
+ return urls
91
+ }
92
+
56
93
export function extractJSXAnnotations (
57
94
node : SuperNode ,
58
95
index : number ,
You can’t perform that action at this time.
0 commit comments