mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #1944: rst_prolog breaks file-wide metadata
This commit is contained in:
parent
b1a23817fc
commit
9ed3d51826
1
CHANGES
1
CHANGES
@ -65,6 +65,7 @@ Bugs fixed
|
||||
* #2164: Fix wrong check for pdftex inside sphinx.sty (for graphicx package option).
|
||||
* #2165, #2218: Remove faulty and non-need conditional from sphinx.sty.
|
||||
* Fix broken LaTeX code is generated if unknown language is given
|
||||
* #1944: Fix rst_prolog breaks file-wide metadata
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
@ -38,7 +38,7 @@ from docutils.frontend import OptionParser
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.util import url_re, get_matching_docs, docname_join, split_into, \
|
||||
FilenameUniqDict, get_figtype, import_object, split_index_msg
|
||||
FilenameUniqDict, get_figtype, import_object, split_index_msg, split_docinfo
|
||||
from sphinx.util.nodes import clean_astext, make_refnode, WarningStream, is_translatable
|
||||
from sphinx.util.osutil import SEP, getcwd, fs_encoding
|
||||
from sphinx.util.i18n import find_catalog_files
|
||||
@ -160,11 +160,12 @@ class SphinxFileInput(FileInput):
|
||||
arg = [data]
|
||||
self.app.emit('source-read', self.env.docname, arg)
|
||||
data = arg[0]
|
||||
docinfo, data = split_docinfo(data)
|
||||
if self.env.config.rst_epilog:
|
||||
data = data + '\n' + self.env.config.rst_epilog + '\n'
|
||||
if self.env.config.rst_prolog:
|
||||
data = self.env.config.rst_prolog + '\n' + data
|
||||
return data
|
||||
return docinfo + data
|
||||
|
||||
|
||||
class BuildEnvironment:
|
||||
|
@ -532,3 +532,12 @@ def encode_uri(uri):
|
||||
for (q, v) in parse_qsl(split[3]))
|
||||
split[3] = urlencode(query).decode('ascii')
|
||||
return urlunsplit(split)
|
||||
|
||||
|
||||
def split_docinfo(text):
|
||||
docinfo_re = re.compile('\A((?:\s*:\w+:.*?\n)+)', re.M)
|
||||
result = docinfo_re.split(text, 1)
|
||||
if len(result) == 1:
|
||||
return '', result[0]
|
||||
else:
|
||||
return result[1:]
|
||||
|
@ -8,7 +8,7 @@
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from sphinx.util import encode_uri
|
||||
from sphinx.util import encode_uri, split_docinfo
|
||||
|
||||
|
||||
def test_encode_uri():
|
||||
@ -24,3 +24,20 @@ def test_encode_uri():
|
||||
uri = (u'https://github.com/search?utf8=✓&q=is%3Aissue+is%3Aopen+is%3A'
|
||||
u'sprint-friendly+user%3Ajupyter&type=Issues&ref=searchresults')
|
||||
assert expected, encode_uri(uri)
|
||||
|
||||
|
||||
def test_splitdocinfo():
|
||||
source = "Hello world.\n"
|
||||
docinfo, content = split_docinfo(source)
|
||||
assert docinfo == ''
|
||||
assert content == 'Hello world.\n'
|
||||
|
||||
source = ":orphan:\n\nHello world.\n"
|
||||
docinfo, content = split_docinfo(source)
|
||||
assert docinfo == ':orphan:\n'
|
||||
assert content == '\nHello world.\n'
|
||||
|
||||
source = ":author: Georg Brandl\n:title: Manual of Sphinx\n\nHello world.\n"
|
||||
docinfo, content = split_docinfo(source)
|
||||
assert docinfo == ':author: Georg Brandl\n:title: Manual of Sphinx\n'
|
||||
assert content == '\nHello world.\n'
|
||||
|
Loading…
Reference in New Issue
Block a user