ipython-contrib / jupyter_contrib_nbextensions

A collection of various notebook extensions for Jupyter
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest
Other
5.2k stars 805 forks source link

python-markdown new install fails to render {{var}}. Browser error 'TypeError: marked is not a function ' #1638

Open johnjbarton opened 1 year ago

johnjbarton commented 1 year ago

(New user here) python-markdown seems like a killer feature... but rendering python silently fails for me.

I assume this is some config/install issue. I've not found any debug procedure or hints.

In the browser debugger I see 'TypeError: marked is not a function '. That seems bad ;-)

markdown does render otherwise, just the variable interpolation fails. The double braces and the var are missing:

Davidson Gemer electron velocity {{ dg_electron_velocity }} kg/sec and wavelength {{ dg_wavelength }}

becomes

Davidson Gemer electron velocity kg/sec and wavelength

johnjbarton commented 1 year ago

Looks like the fail is here: html = marked(ul['text/plain']); in python-markdown/main.js. The object ul['text/plain'] is the python value to be displayed.

So the 'marked is not a function' error is symptom, not a cause. The entry in ulhas not been converted to something that markdown can handle.

juhasch commented 1 year ago

This is due to changes in the notebook main code itself. The "marked" library is no longer included there. It can be fixed, but it is a little bit tricky. In case you want to try:

  1. Download the marked.js file from https://cdnjs.com/libraries/marked and copy it to the python-markdown extension directory
  2. Replace 'components/marked/lib/marked',with nbextensions/python-markdown/marked.min',
  3. Replace all calls to marked(...) by marked.marked(...) calls in main.js of the extension.
johnjbarton commented 1 year ago

Thanks. Do you have any posts on the nbextensions transition?

I have to say that the choice between no extensions (all disabled by default) and extensions that just fail makes the platform very unattractive. I would have expected a "stable" distribution with old extensions and a "beta" distribution for transitions.

On Sun, May 7, 2023 at 1:05 PM Juergen Hasch @.***> wrote:

This is due to changes in the notebook main code itself. The "marked" library is no longer included there. It can be fixed, but it is a little bit tricky. In case you want to try:

  1. Download the marked.js file from https://cdnjs.com/libraries/marked and copy it to the python-markdown extension directory
  2. Replace 'components/marked/lib/marked',with nbextensions/python-markdown/marked.min',
  3. Replace all calls to marked(...) by marked.marked(...) calls in main.js of the extension.

— Reply to this email directly, view it on GitHub https://github.com/ipython-contrib/jupyter_contrib_nbextensions/issues/1638#issuecomment-1537529703, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABSGATYIWR25LZNZFSBVBDXE76BLANCNFSM6AAAAAAXYPZHOY . You are receiving this because you authored the thread.Message ID: <ipython-contrib/jupyter_contrib_nbextensions/issues/1638/1537529703@ github.com>

johnjbarton commented 1 year ago

Ok I cloned the repo and edited per your instructions. I used https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/CONTRIBUTING.md#setup-development but when I run jupyter notebook I still get the original main.js, rather than my modified one.

Where might I ask about dev setup issues?

Is committing marked.min to python-markdown/ in the plan for v6+?

Maybe the two different marked libs could both be required and have a runtime test/fallback?

johnjbarton commented 1 year ago

I accidently noticed that on the nbextensions_configurator tab there was an info panel: "This nbextension's require url (python-markdown/main) is referenced by two different yaml files on the server." The server log confirms that this duplicate issue.

I don't recognize either path however, eg [W 17:18:10.571 NotebookApp] [jupyter_nbextensions_configurator] nbextension 'python-markdown/main' has duplicate listings in both 'C:\Users\jjb\AppData\Local\Programs\Python\Python311\share\jupyter\nbextensions\python-markdown\python-markdown.yaml' and 'C:\Users\jjb\AppData\Roaming\jupyter\nbextensions\python-markdown\python-markdown.yaml'

There must be some server config that points now to two roots for nbextensions.

johnjbarton commented 1 year ago

Using this hint I ran jupyter contrib nbextensions uninstall --user and the duplicates are gone and the Python variable interpolation works.

johnjbarton commented 1 year ago

Unfortunately I succeeded by dumb luck. I made more edits and these do not appear in the app. I tried various uninstall/install commands but no dice.

It seems as if the app runs off stuff in AppData rather than my git repo directly. Some command must copy files into the AppData.

The command jupyter contrib nbextension install --user did the trick. IDK why.

johnjbarton commented 1 year ago

My fix is in https://github.com/ipython-contrib/jupyter_contrib_nbextensions/pull/1639

bradenmitchell commented 11 months ago

Any update on this? I am having the same issues outputting just the example'a = 1.23' '{{a}}' in the extensions documentation.

phlummox commented 10 months ago

@bradenmitchell I don't know if it is useful, but I can confirm that @johnjbarton's patches work, at least for me. You should be able to use them, instead of the default Jupyter notebook extensions, by running:

pip install 'git+https://github.com/johnjbarton/jupyter_contrib_nbextensions.git@84aeb3b0c9880d47c562d80d5155fb87caaecac2'

(Probably best to do so in a venv.)

I've also got a small docker-compose example demonstrating them - details below.

docker-compose example of johnjbarton's patches in use
Dockerfile: ```dockerfile FROM jupyter/base-notebook:notebook-6.5.4 USER root RUN \ apt-get update && \ apt-get --no-install-recommends install -yq \ git USER jovyan # (not sure if ipykernel need to be upgraded, but some posts # on this bug thread report it might) RUN \ pip install --no-cache-dir --user --upgrade \ ipykernel \ 'git+https://github.com/johnjbarton/jupyter_contrib_nbextensions.git@84aeb3b0c9880d47c562d80d5155fb87caaecac2' # also, jupyter_lsp seems not to work and throws errors on server # startup, so we disable it. RUN \ export PATH=$HOME/.local/bin:$PATH \ && jupyter contrib nbextension install --user \ && jupyter nbclassic-extension enable python-markdown/main --user \ && jupyter serverextension disable jupyter_lsp \ && fix-permissions "${CONDA_DIR}" \ && fix-permissions "/home/${NB_USER}" RUN \ echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc ``` docker-compose.yml: ```yml version: '3' services: jupyter: build: . ports: - "8888:8888" volumes: - ".:/home/jovyan/work" environment: - "DOCKER_STACKS_JUPYTER_CMD=notebook" ``` mynotebook.ipynb: ```json { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "30e30612", "metadata": {}, "outputs": [], "source": [ "x = \"some value\"" ] }, { "cell_type": "markdown", "id": "d20c6c3a", "metadata": { "variables": { "repr(x)": ""'some value'"" } }, "source": [ "The value of x is {{repr(x)}}\n" ] }, { "cell_type": "code", "execution_count": null, "id": "22f26b7d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 5 } ``` To use this example, run `docker-compose up`.

@juhasch or other maintainers - are the patches suggested by johnjbarton likely to be incorporated into the repo, thus fixing this bug?