mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
00ccf29b50
commit
af6f312d9e
@ -23,9 +23,7 @@ custom
|
|||||||
# General configuration
|
# General configuration
|
||||||
# ---------------------
|
# ---------------------
|
||||||
|
|
||||||
needs_sphinx = '1.0'
|
needs_sphinx = '1.2'
|
||||||
|
|
||||||
rst_prolog = '.. |app| replace:: %s' % __appname__
|
|
||||||
|
|
||||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||||
# coming with Sphinx (named 'sphinx.addons.*') or your custom ones.
|
# coming with Sphinx (named 'sphinx.addons.*') or your custom ones.
|
||||||
|
@ -10,6 +10,7 @@ del init_calibre
|
|||||||
from sphinx.util.console import bold
|
from sphinx.util.console import bold
|
||||||
|
|
||||||
sys.path.append(os.path.abspath('../../../'))
|
sys.path.append(os.path.abspath('../../../'))
|
||||||
|
from calibre import __appname__
|
||||||
from calibre.linux import entry_points, cli_index_strings
|
from calibre.linux import entry_points, cli_index_strings
|
||||||
from epub import EPUBHelpBuilder
|
from epub import EPUBHelpBuilder
|
||||||
from latex import LaTeXHelpBuilder
|
from latex import LaTeXHelpBuilder
|
||||||
@ -17,13 +18,18 @@ from latex import LaTeXHelpBuilder
|
|||||||
def substitute(app, doctree):
|
def substitute(app, doctree):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
include_pat = re.compile(r'^.. include:: (\S+.rst)', re.M)
|
||||||
|
|
||||||
def source_read_handler(app, docname, source):
|
def source_read_handler(app, docname, source):
|
||||||
source[0] = source[0].replace('/|lang|/', '/%s/' % app.config.language)
|
src = source[0]
|
||||||
if docname == 'index':
|
src = src.replace('|lang|', app.config.language)
|
||||||
|
src = src.replace('|app|', __appname__)
|
||||||
# Sphinx does not call source_read_handle for the .. include directive
|
# Sphinx does not call source_read_handle for the .. include directive
|
||||||
ss = [open('simple_index.rst', 'rb').read().decode('utf-8')]
|
for m in reversed(tuple(include_pat.finditer(src))):
|
||||||
source_read_handler(app, 'simple_index', ss)
|
ss = [open(m.group(1)).read().decode('utf-8')]
|
||||||
source[0] = source[0].replace('.. include:: simple_index.rst', ss[0])
|
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_INDEX='''
|
||||||
.. _cli:
|
.. _cli:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user