Source code for ipypublish.preprocessors.latex_doc_links

import logging
import os
from binascii import a2b_base64
import sys
import json
import re
from mimetypes import guess_extension

from six import string_types
import traitlets as traits
from nbconvert.preprocessors import Preprocessor

if sys.version_info[0] == 2:
    from urlparse import urlparse
else:
    from urllib.parse import urlparse

logger = logging.getLogger("resolve_links")


[docs]def guess_extension_without_jpe(mimetype): """ 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 """ ext = guess_extension(mimetype) if ext == ".jpe": ext = ".jpeg" return ext
[docs]def resolve_path(fpath, filepath): """resolve a relative path, w.r.t. another filepath """ if is_hyperlink(fpath): return fpath if not os.path.isabs(fpath): fpath = os.path.join(os.path.dirname(str(filepath)), fpath) fpath = os.path.abspath(fpath) return os.path.normpath(fpath)