Skip to content

Commit

Permalink
Restore support for list-style source_suffix with third-party par…
Browse files Browse the repository at this point in the history
…sers (#12584)
  • Loading branch information
AA-Turner authored Jul 15, 2024
1 parent a874246 commit 55c8953
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Release 7.4.3 (in development)
Bugs fixed
----------

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

Release 7.4.2 (released Jul 15, 2024)
=====================================
Expand Down
10 changes: 7 additions & 3 deletions sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,17 @@ def convert_source_suffix(app: Sphinx, config: Config) -> None:
# The default filetype is determined on later step.
# By default, it is considered as restructuredtext.
config.source_suffix = {source_suffix: 'restructuredtext'}
logger.info(__("Converting `source_suffix = %r` to `source_suffix = %r`."),
source_suffix, config.source_suffix)
elif isinstance(source_suffix, (list, tuple)):
# if list, considers as all of them are default filetype
config.source_suffix = dict.fromkeys(source_suffix, 'restructuredtext')
logger.info(__("Converting `source_suffix = %r` to `source_suffix = %r`."),
source_suffix, config.source_suffix)
elif not isinstance(source_suffix, dict):
logger.warning(__("The config value `source_suffix' expects "
"a string, list of strings, or dictionary. "
"But `%r' is given." % source_suffix))
msg = __("The config value `source_suffix' expects a dictionary,"
"a string, or a list of strings. Got `%r' instead (type %s).")
raise ConfigError(msg % (source_suffix, type(source_suffix)))


def convert_highlight_options(app: Sphinx, config: Config) -> None:
Expand Down
8 changes: 6 additions & 2 deletions sphinx/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,14 @@ def merge_source_suffix(app: Sphinx, config: Config) -> None:
for suffix, filetype in app.registry.source_suffix.items():
if suffix not in app.config.source_suffix: # NoQA: SIM114
app.config.source_suffix[suffix] = filetype
elif app.config.source_suffix[suffix] is None:
# filetype is not specified (default filetype).
elif app.config.source_suffix[suffix] == 'restructuredtext':
# The filetype is not specified (default filetype).
# So it overrides default filetype by extensions setting.
app.config.source_suffix[suffix] = filetype
elif app.config.source_suffix[suffix] is None:
msg = __('`None` is not a valid filetype for %r.') % suffix
logger.warning(msg)
app.config.source_suffix[suffix] = filetype

# copy config.source_suffix to registry
app.registry.source_suffix = app.config.source_suffix
Expand Down

0 comments on commit 55c8953

Please sign in to comment.