Skip to content

Commit 516d1a2

Browse files
committed
Add "source_encoding" config value.
1 parent 918fbec commit 516d1a2

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ New features added
5555
- Added ``exclude_dirnames`` config value that can be used to exclude
5656
e.g. CVS directories from source file search.
5757

58+
- Added ``source_encoding`` config value to select input encoding.
59+
5860
* Extensions:
5961

6062
- The new extensions ``sphinx.ext.jsmath`` and ``sphinx.ext.pngmath``

doc/config.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ General configuration
6767
.. confval:: source_suffix
6868

6969
The file name extension of source files. Only files with this suffix will be
70-
read as sources. Default is ``.rst``.
70+
read as sources. Default is ``'.rst'``.
7171

72+
.. confval:: source_encoding
73+
74+
The encoding of all reST source files. The recommended encoding, and the
75+
default value, is ``'utf-8'``.
76+
77+
.. versionadded:: 0.5
78+
Previously, Sphinx accepted only UTF-8 encoded sources.
79+
7280
.. confval:: master_doc
7381

7482
The document name of the "master" document, that is, the document that

sphinx/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Config(object):
3535

3636
master_doc = ('contents', True),
3737
source_suffix = ('.rst', True),
38+
source_encoding = ('utf-8', True),
3839
unused_docs = ([], True),
3940
exclude_dirs = ([], True),
4041
exclude_trees = ([], True),

sphinx/environment.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,14 @@ def read(self):
496496
return data
497497

498498
self.docname = docname
499-
doctree = publish_doctree(None, src_path, SphinxSourceClass,
500-
settings_overrides=self.settings,
501-
reader=SphinxStandaloneReader())
499+
self.settings['input_encoding'] = self.config.source_encoding
500+
try:
501+
doctree = publish_doctree(None, src_path, SphinxSourceClass,
502+
settings_overrides=self.settings,
503+
reader=SphinxStandaloneReader())
504+
except UnicodeError, err:
505+
from sphinx.application import SphinxError
506+
raise SphinxError(err.message)
502507
self.filter_messages(doctree)
503508
self.process_dependencies(docname, doctree)
504509
self.process_images(docname, doctree)

sphinx/quickstart.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
# The suffix of source filenames.
5555
source_suffix = '%(suffix)s'
5656
57+
# The encoding of source files.
58+
#source_encoding = 'utf-8'
59+
5760
# The master toctree document.
5861
master_doc = '%(master)s'
5962

0 commit comments

Comments
 (0)