Skip to content

Commit 55c8953

Browse files
authored
Restore support for list-style source_suffix with third-party parsers (#12584)
1 parent a874246 commit 55c8953

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

CHANGES.rst

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Release 7.4.3 (in development)
44
Bugs fixed
55
----------
66

7+
* #12582: Restore support for list-styled :confval:`source_suffix` values
8+
with extensions that register parsers.
9+
Patch by Adam Turner.
710

811
Release 7.4.2 (released Jul 15, 2024)
912
=====================================

sphinx/config.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,17 @@ def convert_source_suffix(app: Sphinx, config: Config) -> None:
582582
# The default filetype is determined on later step.
583583
# By default, it is considered as restructuredtext.
584584
config.source_suffix = {source_suffix: 'restructuredtext'}
585+
logger.info(__("Converting `source_suffix = %r` to `source_suffix = %r`."),
586+
source_suffix, config.source_suffix)
585587
elif isinstance(source_suffix, (list, tuple)):
586588
# if list, considers as all of them are default filetype
587589
config.source_suffix = dict.fromkeys(source_suffix, 'restructuredtext')
590+
logger.info(__("Converting `source_suffix = %r` to `source_suffix = %r`."),
591+
source_suffix, config.source_suffix)
588592
elif not isinstance(source_suffix, dict):
589-
logger.warning(__("The config value `source_suffix' expects "
590-
"a string, list of strings, or dictionary. "
591-
"But `%r' is given." % source_suffix))
593+
msg = __("The config value `source_suffix' expects a dictionary,"
594+
"a string, or a list of strings. Got `%r' instead (type %s).")
595+
raise ConfigError(msg % (source_suffix, type(source_suffix)))
592596

593597

594598
def convert_highlight_options(app: Sphinx, config: Config) -> None:

sphinx/registry.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,14 @@ def merge_source_suffix(app: Sphinx, config: Config) -> None:
504504
for suffix, filetype in app.registry.source_suffix.items():
505505
if suffix not in app.config.source_suffix: # NoQA: SIM114
506506
app.config.source_suffix[suffix] = filetype
507-
elif app.config.source_suffix[suffix] is None:
508-
# filetype is not specified (default filetype).
507+
elif app.config.source_suffix[suffix] == 'restructuredtext':
508+
# The filetype is not specified (default filetype).
509509
# So it overrides default filetype by extensions setting.
510510
app.config.source_suffix[suffix] = filetype
511+
elif app.config.source_suffix[suffix] is None:
512+
msg = __('`None` is not a valid filetype for %r.') % suffix
513+
logger.warning(msg)
514+
app.config.source_suffix[suffix] = filetype
511515

512516
# copy config.source_suffix to registry
513517
app.registry.source_suffix = app.config.source_suffix

0 commit comments

Comments
 (0)