@@ -29,6 +29,10 @@ pub const fn is_valid_ident(s: &str) -> bool {
29
29
matches ! ( s. as_bytes( ) [ 0 ] , b'a' ..=b'z' | b'A' ..=b'Z' | b'_' )
30
30
}
31
31
32
+ pub fn skip_doc_link_sym ( s : & str ) -> bool {
33
+ matches ! ( s, "SDL_image" | "SDL_MAIN_USE_CALLBACKS" )
34
+ }
35
+
32
36
fn emit_extern_start ( ctx : & mut EmitContext , abi : & Option < FnAbi > , for_fn_ptr : bool ) -> EmitResult {
33
37
if let Some ( abi) = & abi {
34
38
match abi. ident . as_str ( ) {
@@ -219,17 +223,19 @@ impl DocComment {
219
223
if i < i0 {
220
224
continue ;
221
225
}
222
- write ! ( patched, "{}" , & line[ i0..i] ) ?;
223
226
quoted += line[ i0..i] . chars ( ) . filter ( |c| * c == '`' ) . count ( ) ;
224
- i0 = i;
225
227
226
- if quoted & 1 == 0 {
228
+ if ( quoted & 1 == 0 )
229
+ || ( line. as_bytes ( ) . get ( i. wrapping_sub ( 1 ) ) . copied ( ) == Some ( b'`' )
230
+ && line. as_bytes ( ) . get ( i. wrapping_sub ( 2 ) ) . copied ( ) != Some ( b'[' ) )
231
+ {
227
232
if ( line[ i..] . starts_with ( "https://" ) || line[ i..] . starts_with ( "http://" ) )
228
233
&& ( i == 0
229
234
|| line. as_bytes ( ) [ i - 1 ] . is_ascii_whitespace ( )
230
235
|| ( line. as_bytes ( ) [ i - 1 ] == b'('
231
236
&& line. as_bytes ( ) . get ( i. saturating_sub ( 2 ) ) . copied ( ) != Some ( b']' ) ) )
232
237
{
238
+ write ! ( patched, "{}" , & line[ i0..i] ) ?;
233
239
i0 = i + line[ i..]
234
240
. find ( |c : char | {
235
241
c. is_ascii_whitespace ( )
@@ -241,26 +247,51 @@ impl DocComment {
241
247
} else if line[ i..] . starts_with ( "SDL_" )
242
248
&& ( i == 0
243
249
|| line. as_bytes ( ) [ i - 1 ] . is_ascii_whitespace ( )
244
- || line. as_bytes ( ) [ i - 1 ] == b'(' )
250
+ || line. as_bytes ( ) [ i - 1 ] == b'('
251
+ || ( line. as_bytes ( ) [ i - 1 ] == b'`'
252
+ && line. as_bytes ( ) . get ( i. wrapping_sub ( 2 ) ) . copied ( ) != Some ( b'[' ) ) )
245
253
{
246
- let end = i + line[ i..]
254
+ let mut end = i + line[ i..]
247
255
. find ( |c : char | !c. is_ascii_alphanumeric ( ) && c != '_' )
248
256
. unwrap_or ( line. len ( ) - i) ;
249
- if line. len ( ) == end
250
- || line. as_bytes ( ) [ end] . is_ascii_whitespace ( )
251
- || matches ! ( line. as_bytes( ) [ end] , b')' | b',' | b'.' | b';' )
252
- || ( line. as_bytes ( ) [ end] == b'('
253
- && line. as_bytes ( ) . get ( end + 1 ) . copied ( ) == Some ( b')' ) )
257
+ if end > i + 4
258
+ && !skip_doc_link_sym ( & line[ i..end] )
259
+ && ( line. len ( ) == end
260
+ || line. as_bytes ( ) [ end] . is_ascii_whitespace ( )
261
+ || matches ! (
262
+ line. as_bytes( ) [ end] ,
263
+ b')' | b',' | b'.' | b';' | b':' | b'`'
264
+ )
265
+ || ( line. as_bytes ( ) [ end] == b'('
266
+ && line. as_bytes ( ) . get ( end + 1 ) . copied ( ) == Some ( b')' ) ) )
267
+ && ( quoted & 1 == 0 || line. as_bytes ( ) [ end] == b'`' )
254
268
{
255
- i0 = end;
256
- if line. as_bytes ( ) . get ( i0) . copied ( ) == Some ( b'(' )
257
- && line. as_bytes ( ) . get ( i0 + 1 ) . copied ( ) == Some ( b')' )
269
+ if line. as_bytes ( ) . get ( end) . copied ( ) == Some ( b'(' )
270
+ && line. as_bytes ( ) . get ( end + 1 ) . copied ( ) == Some ( b')' )
258
271
{
259
- i0 += 2 ;
272
+ end += 2 ;
273
+ }
274
+ if quoted & 1 == 0 {
275
+ write ! ( patched, "{}" , & line[ i0..i] ) ?;
276
+ write ! ( patched, "[`{}`]" , & line[ i..end] ) ?;
277
+ i0 = end;
278
+ } else {
279
+ write ! ( patched, "{}" , & line[ i0..i - 1 ] ) ?;
280
+ write ! ( patched, "[{}]" , & line[ i - 1 ..end + 1 ] ) ?;
281
+ i0 = end + 1 ;
282
+ quoted += 1 ;
260
283
}
261
- write ! ( patched, "[`{}`]" , & line[ i..i0] ) ?;
284
+ } else {
285
+ write ! ( patched, "{}" , & line[ i0..i] ) ?;
286
+ i0 = i;
262
287
}
288
+ } else {
289
+ write ! ( patched, "{}" , & line[ i0..i] ) ?;
290
+ i0 = i;
263
291
}
292
+ } else {
293
+ write ! ( patched, "{}" , & line[ i0..i] ) ?;
294
+ i0 = i;
264
295
}
265
296
}
266
297
write ! ( patched, "{}" , & line[ i0..] ) ?;
0 commit comments