summaryrefslogtreecommitdiff
path: root/sphinx/util/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util/__init__.py')
-rw-r--r--sphinx/util/__init__.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index d44290b7b..2032b94ac 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -29,7 +29,9 @@ from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, S
from urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode
from sphinx.deprecation import RemovedInSphinx40Warning
-from sphinx.errors import PycodeError, SphinxParallelError, ExtensionError
+from sphinx.errors import (
+ PycodeError, SphinxParallelError, ExtensionError, FiletypeNotFoundError
+)
from sphinx.locale import __
from sphinx.util import logging
from sphinx.util.console import strip_colors, colorize, bold, term_width_line # type: ignore
@@ -117,6 +119,16 @@ def get_matching_docs(dirname: str, suffixes: List[str],
break
+def get_filetype(source_suffix, filename):
+ # type: (Dict[str, str], str) -> str
+ for suffix, filetype in source_suffix.items():
+ if filename.endswith(suffix):
+ # If default filetype (None), considered as restructuredtext.
+ return filetype or 'restructuredtext'
+ else:
+ raise FiletypeNotFoundError
+
+
class FilenameUniqDict(dict):
"""
A dictionary that automatically generates unique names for its keys,