ipypublish.preprocessors.latex_doc_links module¶
-
class
ipypublish.preprocessors.latex_doc_links.LatexDocLinks(*args, **kwargs)[source]¶ Bases:
nbconvert.preprocessors.base.Preprocessora preprocessor to resolve file paths in the notebook:
Extract attachments from markdown cells, to resources[‘outputs’], and redirect their file links to self.filesfolder
If nb.metadata.ipub.bibliography, create resources[‘bibliopath’]
Creates resources[‘external_file_paths’] = [] and adds to it:
local relative file paths referenced in markdown cells by ‘[](path/to/file)’
path to nb.metadata.ipub.bibliography (if present)
path to nb.metadata.ipub.titlepage.logo (if present)
If self.redirect_external=True, redirects relative external file paths to self.filesfolder
-
extract_attachments¶ A boolean (True, False) trait.
-
filesfolder¶ A trait for unicode strings.
-
metapath¶ A trait for unicode strings.
-
output_attachment_template¶ A trait for unicode strings.
-
preprocess_cell(cell, resources, cell_index)[source]¶ Extract attachment
- Parameters
cell (nbformat.notebooknode.NotebookNode) – Notebook cell being processed
resources (dict) – Additional resources used in the conversion process. Allows preprocessors to pass variables into the Jinja engine.
cell_index (int) – Index of the cell being processed
-
redirect_external¶ A boolean (True, False) trait.
-
ipypublish.preprocessors.latex_doc_links.extract_file_links(source, parent_path, redirect_path, replace_nonexistent=False)[source]¶ extract local linked files
Examples
>>> import os, pytest >>> if os.name == 'nt': ... pytest.skip()
>>> source = '''## Cell with Linked Image ...  ... a [test_link](other_doc#a-link)''' >>> src, rpaths, npaths = extract_file_links( ... source, '/root/nb.ipynb', 'redirect', True) >>> print(src) ## Cell with Linked Image  a [test_link](redirect/other_doc#a-link)
>>> print(rpaths[0]) /root/subdir/logo_example.png >>> print(rpaths[1]) /root/other_doc
-
ipypublish.preprocessors.latex_doc_links.guess_extension_without_jpe(mimetype)[source]¶ This function fixes a problem with ‘.jpe’ extensions of jpeg images which are then not recognised by latex. For any other case, the function works in the same way as mimetypes.guess_extension
-
ipypublish.preprocessors.latex_doc_links.is_hyperlink(path)[source]¶ test whether a path is a hyperlink, e.g. https://site.org