User Manual: Ensure the |lang| and |app| substitutions work everywhere

Also ensure that *all* .. include directives have their substitutions
properly processed, in case I add any more in the future.
This commit is contained in:
Kovid Goyal 2014-10-06 09:17:56 +05:30
parent 00ccf29b50
commit af6f312d9e
2 changed files with 13 additions and 9 deletions

View File

@ -23,9 +23,7 @@ custom
# General configuration
# ---------------------
needs_sphinx = '1.0'
rst_prolog = '.. |app| replace:: %s' % __appname__
needs_sphinx = '1.2'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.addons.*') or your custom ones.

View File

@ -10,6 +10,7 @@ del init_calibre
from sphinx.util.console import bold
sys.path.append(os.path.abspath('../../../'))
from calibre import __appname__
from calibre.linux import entry_points, cli_index_strings
from epub import EPUBHelpBuilder
from latex import LaTeXHelpBuilder
@ -17,13 +18,18 @@ from latex import LaTeXHelpBuilder
def substitute(app, doctree):
pass
include_pat = re.compile(r'^.. include:: (\S+.rst)', re.M)
def source_read_handler(app, docname, source):
source[0] = source[0].replace('/|lang|/', '/%s/' % app.config.language)
if docname == 'index':
# Sphinx does not call source_read_handle for the .. include directive
ss = [open('simple_index.rst', 'rb').read().decode('utf-8')]
source_read_handler(app, 'simple_index', ss)
source[0] = source[0].replace('.. include:: simple_index.rst', ss[0])
src = source[0]
src = src.replace('|lang|', app.config.language)
src = src.replace('|app|', __appname__)
# Sphinx does not call source_read_handle for the .. include directive
for m in reversed(tuple(include_pat.finditer(src))):
ss = [open(m.group(1)).read().decode('utf-8')]
source_read_handler(app, m.group(1).partition('.')[0], ss)
src = src[:m.start()] + ss[0] + src[m.end():]
source[0] = src
CLI_INDEX='''
.. _cli: