jfbercher / jupyter_latex_envs

(Some) LaTeX environments for Jupyter
Other
112 stars 27 forks source link

latex_envs blocks Pasting images from clipboard #55

Closed ducha-aiki closed 2 years ago

ducha-aiki commented 4 years ago

Description:

When pasting the embedded image from clipboard like ![image.png](attachment:image.png), it is not displayed until latex_envs is on. If one turns off latex_envs, renders the cell and then turns on, then it works.

darkfishy commented 4 years ago

I found the source of this error in the overridden render method. To fix it in one's local setup, one needs to modify the latex_envs.js file under the user's local or system or both version(s) of nbextensions installation.

Assuming local file is at $HOME/.local/share/jupyter/nbextensions/latex_envs/latex_envs.js, add the following code

// replace attachment:<key> by the corresponding entry
// in the cell's attachments
html.find('img[src^="attachment:"]').each(function (i, h) {
    h       = $(h);
    var key = h.attr('src').replace(/^attachment:/, '');

    if (that.attachments.hasOwnProperty(key)) {
        var att  = that.attachments[key];
        var mime = Object.keys(att)[0];
        h.attr('src', 'data:' + mime + ';base64,' + att[mime]);
    } else {
        h.attr('src', '');
    }
});

after the lines

// links in markdown cells should open in new tabs
html.find("a[href]").not('[href^="#"]').attr("target", "_blank");

in the function override_mdrenderer()