mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Select an image by similarity if multiple images are globbed by `.. image:: filename.*`
Until this point, it is used the last image returned from glob.glob(). The order of glob.glob() is determined by filesystem. After this, Sphinx uses filename similarity to determine the image.
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -105,6 +105,7 @@ Features added
|
||||
* #1853: support custom text splitter on html search with ``language='ja'``.
|
||||
* #2320: classifier of glossary terms can be used for index entries grouping key.
|
||||
The classifier also be used for translation. See also :ref:`glossary-directive`.
|
||||
* Select an image by similarity if multiple images are globbed by ``.. image:: filename.*``
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
@@ -899,15 +899,18 @@ class BuildEnvironment:
|
||||
# set imgpath as default URI
|
||||
node['uri'] = rel_imgpath
|
||||
if rel_imgpath.endswith(os.extsep + '*'):
|
||||
globbed = {}
|
||||
for filename in glob(full_imgpath):
|
||||
new_imgpath = relative_path(path.join(self.srcdir, 'dummy'),
|
||||
filename)
|
||||
try:
|
||||
mimetype = guess_mimetype(filename)
|
||||
candidates[mimetype] = new_imgpath
|
||||
globbed.setdefault(mimetype, []).append(new_imgpath)
|
||||
except (OSError, IOError) as err:
|
||||
self.warn_node('image file %s not readable: %s' %
|
||||
(filename, err), node)
|
||||
for key, files in iteritems(globbed):
|
||||
candidates[key] = sorted(files, key=len)[0] # select by similarity
|
||||
else:
|
||||
candidates['*'] = rel_imgpath
|
||||
|
||||
|
||||
BIN
tests/roots/test-image-glob/img.ja.png
Normal file
BIN
tests/roots/test-image-glob/img.ja.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
BIN
tests/roots/test-image-glob/img.zh.png
Normal file
BIN
tests/roots/test-image-glob/img.zh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
Reference in New Issue
Block a user