@@ -124,6 +124,7 @@ def _wrap_full_document(self, html_fragment_or_doc: str) -> str:
124
124
text = html_fragment_or_doc .lstrip ()
125
125
126
126
# Already a full document? Return as-is.
127
+ # only look at the first ~2KB to avoid scanning huge strings.
127
128
lowered = text [:2000 ].lower ()
128
129
if lowered .startswith ("<!doctype" ) or "<html" in lowered :
129
130
return html_fragment_or_doc
@@ -168,14 +169,10 @@ def _replace_files(self, text: str, inline: bool = False, size_check: bool = Fal
168
169
169
170
patterns = []
170
171
if ver :
171
- patterns .append (f"{ self ._static_url } ansys{ ver } /" ) # custom
172
- patterns .append (f"/static/ansys{ ver } /" ) # legacy literal
173
-
174
- # custom first, then legacy literals
175
- patterns .extend ([self ._static_url , self ._media_url , "/static/" , "/media/" ])
176
-
172
+ patterns .append (f"{ self ._static_url } ansys{ ver } /" )
173
+ patterns .extend ([self ._static_url , self ._media_url ])
177
174
if ver :
178
- patterns .append (f"/ansys{ ver } /" ) # server-root style
175
+ patterns .append (f"/ansys{ ver } /" )
179
176
180
177
while True :
181
178
# Find the next match using the legacy priority order
@@ -361,15 +358,10 @@ def _process_file(self, path_in_html: str, pathname: str, inline: bool = False)
361
358
# Resolve source file location based on the raw pathname (no normalization)
362
359
ver = str (self ._ansys_version ) if self ._ansys_version is not None else ""
363
360
364
- # Source resolution: custom first, then legacy literals
365
361
if pathname .startswith (self ._media_url ):
366
362
source_file = self ._media_dir / pathname .replace (self ._media_url , "" , 1 )
367
363
elif pathname .startswith (self ._static_url ):
368
364
source_file = self ._static_dir / pathname .replace (self ._static_url , "" , 1 )
369
- elif pathname .startswith ("/media/" ): # legacy literal
370
- source_file = self ._media_dir / pathname .replace ("/media/" , "" , 1 )
371
- elif pathname .startswith ("/static/" ): # legacy literal
372
- source_file = self ._static_dir / pathname .replace ("/static/" , "" , 1 )
373
365
elif ver and pathname .startswith (f"/ansys{ ver } /" ):
374
366
source_file = self ._static_dir / pathname .lstrip ("/" )
375
367
else :
@@ -417,19 +409,11 @@ def _process_file(self, path_in_html: str, pathname: str, inline: bool = False)
417
409
else :
418
410
content = self ._fix_viewer_component_paths (basename , content )
419
411
420
- # Output path:
421
- # keep ansys tree if the input path came from /static/ansys{ver}/ (custom OR legacy literal)
422
- if ver and (
423
- pathname .startswith (f"{ self ._static_url } ansys{ ver } /" )
424
- or pathname .startswith (f"/static/ansys{ ver } /" )
425
- ):
426
- local_pathname = os .path .dirname (pathname )
427
- # normalize either custom or legacy /static/ to './'
428
- if local_pathname .startswith (self ._static_url ):
429
- local_pathname = local_pathname .replace (self ._static_url , "./" , 1 )
430
- elif local_pathname .startswith ("/static/" ):
431
- local_pathname = local_pathname .replace ("/static/" , "./" , 1 )
432
-
412
+ # Output path (exact legacy behavior):
413
+ # - If /static/ansys{ver}/ -> keep ansys tree, remove '/static/' -> './ansys{ver}/.../<basename>'
414
+ # - Else -> './media/<basename>'
415
+ if ver and pathname .startswith (f"{ self ._static_url } ansys{ ver } /" ):
416
+ local_pathname = os .path .dirname (pathname ).replace (self ._static_url , "./" , 1 )
433
417
result = f"{ local_pathname } /{ basename } "
434
418
target_file = self ._output_dir / local_pathname .lstrip ("./" ) / basename
435
419
else :
@@ -445,12 +429,12 @@ def _process_file(self, path_in_html: str, pathname: str, inline: bool = False)
445
429
def _find_block (self , text : str , start : int , prefix : str , suffix : str ) -> tuple [int , int , str ]:
446
430
"""
447
431
Legacy-compatible: return the next [prefix ... suffix] block that contains at least
448
- one asset-like reference. Accept both the literal legacy prefixes and the configured
449
- custom prefixes. Also accept any ' /ansys<ver>/' or generic '/ansys<digits>/' .
432
+ one asset-like reference. Accept the configured custom prefixes and the dynamic
433
+ /ansys<ver>/ root. No hard-coded legacy literals .
450
434
"""
451
- # Normalize known prefixes (custom URLs may differ from /static/ and /media/)
452
435
custom_static = (self ._static_url or "" ).strip ()
453
436
custom_media = (self ._media_url or "" ).strip ()
437
+ ver = str (self ._ansys_version ) if self ._ansys_version is not None else ""
454
438
455
439
while True :
456
440
try :
@@ -462,14 +446,13 @@ def _find_block(self, text: str, start: int, prefix: str, suffix: str) -> tuple[
462
446
except ValueError :
463
447
return - 1 , - 1 , ""
464
448
idx2 += len (suffix )
449
+
465
450
block = text [idx1 :idx2 ]
466
451
467
452
if (
468
- ("/static/" in block )
469
- or ("/media/" in block )
470
- or (custom_static and custom_static in block )
453
+ (custom_static and custom_static in block )
471
454
or (custom_media and custom_media in block )
472
- or re . search ( r "/ansys\d+/" , block ) is not None
455
+ or ( ver and f "/ansys{ ver } /" in block )
473
456
):
474
457
return idx1 , idx2 , block
475
458
0 commit comments