mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added code to replace problematic characters in filenames when using
ImageConverter
This commit is contained in:
parent
23924d4a9c
commit
580afe5b50
@ -9,6 +9,7 @@
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
from hashlib import sha1
|
||||
from math import ceil
|
||||
from typing import Any, Dict, List, Tuple
|
||||
@ -27,6 +28,7 @@ from sphinx.util.osutil import ensuredir, movefile
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MAX_FILENAME_LEN = 32
|
||||
CRITICAL_PATH_CHAR_RE = re.compile('[:;<>|*" ]')
|
||||
|
||||
|
||||
class BaseImageConverter(SphinxTransform):
|
||||
@ -146,6 +148,7 @@ class DataURIExtractor(BaseImageConverter):
|
||||
|
||||
def get_filename_for(filename: str, mimetype: str) -> str:
|
||||
basename = os.path.basename(filename)
|
||||
basename = re.sub(CRITICAL_PATH_CHAR_RE, "_", basename)
|
||||
return os.path.splitext(basename)[0] + get_image_extension(mimetype)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user