sphinx.py
50 lines
| 1.8 KiB
| text/x-python
|
PythonLexer
Jonathan Frederic
|
r10436 | """Module that allows custom Sphinx parameters to be set on the notebook and | ||
Jonathan Frederic
|
r10674 | on the 'other' object passed into Jinja. Called prior to Jinja conversion | ||
process. | ||||
Jonathan Frederic
|
r9772 | """ | ||
Jonathan Frederic
|
r10436 | #----------------------------------------------------------------------------- | ||
# Copyright (c) 2013, the IPython Development Team. | ||||
# | ||||
# Distributed under the terms of the Modified BSD License. | ||||
# | ||||
# The full license is in the file COPYING.txt, distributed with this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r10674 | |||
Jonathan Frederic
|
r10436 | from __future__ import print_function, absolute_import | ||
Jonathan Frederic
|
r12689 | import os | ||
import sphinx | ||||
from .base import Preprocessor | ||||
Jonathan Frederic
|
r10674 | |||
Jonathan Frederic
|
r10436 | #----------------------------------------------------------------------------- | ||
# Classes and functions | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r10674 | |||
Paul Ivanov
|
r12219 | class SphinxPreprocessor(Preprocessor): | ||
Jonathan Frederic
|
r9772 | """ | ||
Paul Ivanov
|
r12219 | Sphinx utility preprocessor. | ||
Jonathan Frederic
|
r9772 | |||
Paul Ivanov
|
r12219 | This preprocessor is used to set variables needed by the latex to build | ||
Jonathan Frederic
|
r9772 | Sphinx stylized templates. | ||
""" | ||||
Paul Ivanov
|
r12219 | def preprocess(self, nb, resources): | ||
Jonathan Frederic
|
r9775 | """ | ||
Paul Ivanov
|
r12219 | Sphinx preprocessing to apply on each notebook. | ||
Jonathan Frederic
|
r10674 | |||
Parameters | ||||
---------- | ||||
nb : NotebookNode | ||||
Notebook being converted | ||||
resources : dictionary | ||||
Additional resources used in the conversion process. Allows | ||||
Paul Ivanov
|
r12219 | preprocessors to pass variables into the Jinja engine. | ||
Jonathan Frederic
|
r9775 | """ | ||
Jonathan Frederic
|
r12689 | |||
Jonathan Frederic
|
r9772 | # Find and pass in the path to the Sphinx dependencies. | ||
Jonathan Frederic
|
r12689 | resources["sphinx"] = {} | ||
MinRK
|
r12055 | resources["sphinx"]["texinputs"] = os.path.realpath(os.path.join(sphinx.package_dir, "texinputs")) | ||
Jonathan Frederic
|
r10674 | return nb, resources | ||