ipypublish
latest

Using IPyPublish

  • 1. Getting Started
  • 2. Writing Code and Formatting Output
  • 3. Writing Markdown
  • 4. Notebook Conversion
  • 5. Metadata Tags
  • 6. Customising the Conversion Process

Sphinx Extensions

  • Introduction
  • ipypublish.sphinx.notebook
  • ipypublish.sphinx.gls

Additional Information

  • Releases
  • Examples
  • IPyPublish In The Wild
  • Developer Guide
  • Additional Tools
  • Acknowledgements
  • Package API
    • ipypublish package
      • Subpackages
        • ipypublish.bib2glossary package
        • ipypublish.convert package
        • ipypublish.export_plugins package
        • ipypublish.filters package
        • ipypublish.filters_pandoc package
        • ipypublish.frontend package
        • ipypublish.port_api package
        • ipypublish.postprocessors package
        • ipypublish.preprocessors package
        • ipypublish.schema package
        • ipypublish.scripts package
        • ipypublish.sphinx package
        • ipypublish.templates package
      • Submodules
      • Module contents

Validation Schemas

  • Document Level Metadata Schema
  • Cell/Output Level Metadata Schema
  • Export Configuration Schema
ipypublish
  • Docs »
  • Package API »
  • ipypublish package »
  • ipypublish.preprocessors package »
  • ipypublish.preprocessors.latex_doc_links module
  • Edit on GitHub

ipypublish.preprocessors.latex_doc_links module¶

class ipypublish.preprocessors.latex_doc_links.LatexDocLinks(*args, **kwargs)[source]¶

Bases: nbconvert.preprocessors.base.Preprocessor

a preprocessor to resolve file paths in the notebook:

  1. Extract attachments from markdown cells, to resources[‘outputs’], and redirect their file links to self.filesfolder

  2. If nb.metadata.ipub.bibliography, create resources[‘bibliopath’]

  3. 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)

  4. 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(nb, resources)[source]¶

Preprocessing to apply on each notebook.

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
... ![test_image](subdir/logo_example.png)
... 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
![test_image](redirect/logo_example.png)
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

ipypublish.preprocessors.latex_doc_links.resolve_path(fpath, filepath)[source]¶

resolve a relative path, w.r.t. another filepath

Next Previous

© Copyright 2017, Chris Sewell Revision 270e9032.

Built with Sphinx using a theme provided by Read the Docs.