figureAltCaption icon indicating copy to clipboard operation
figureAltCaption copied to clipboard

Not working with python-markdown 3 and above

Open Galarzaa90 opened this issue 7 years ago • 8 comments

This does not seem to be working anymore, at least not on mkdocs, I don't have another way to test.

ERROR   -  Config value: 'markdown_extensions'. Error: Failed loading extension "figureAltCaption".

I forked it and checked it, and noticed that there were some imports that weren't valid anymore and removed them, but even then, it kept failing, but now with a different error.

This are the changes I made

ERROR   -  Config value: 'markdown_extensions'. Error: configs

I have no experience with markdown extensions, so I really don't know how to test.

Galarzaa90 avatar Sep 24 '18 05:09 Galarzaa90

Thanks for reporting the issue. I tried with the command line version of python markdown and it seems to work well for me: cat somemarkdown.md | python3 -m markdown -x figureAltCaption

My version is 2.6.9 which is what is shown when I execute python3 -m markdown --version

Or do you use the very recent 3.0 version of the markdown extensions? (I have not tried with that one yet)

jdittrich avatar Sep 24 '18 20:09 jdittrich

I think that's definitely the problem, they introduced many breaking changes in 3.0 :(

I tried manually downgraded to Markdown 2.6.*, but then it breaks the requirements because of pymdown-extensions 5.0`.
I'm pretty sure doing those downgrades will make it work again, I will test later.

Have you considered adding this to pypi? It would be a great addition there. It would require implementing a versioning system tho.

Galarzaa90 avatar Sep 24 '18 20:09 Galarzaa90

I think that's definitely the problem, they introduced many breaking changes in 3.0

OK, that seems probable. I will set up an environment and test with 3.0.

Have you considered adding this to pypi? Good idea. I created #5 (Add to pypi)

jdittrich avatar Sep 25 '18 14:09 jdittrich

How can I help? We really need this functionality!

After testing with markdown 3.0.1 in python 3.7.1 I get the following Traceback:

>>> import figureAltCaption
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "miniconda3/envs/mkdocs-new/lib/python3.7/site-packages/figureAltCaption.py", line 33, in <module>
    from markdown.inlinepatterns import IMAGE_LINK_RE, IMAGE_REFERENCE_RE, NOBRACKET, BRK
ImportError: cannot import name 'NOBRACKET' from 'markdown.inlinepatterns' (miniconda3/envs/mkdocs-new/lib/python3.7/site-packages/markdown/inlinepatterns.py)
>>> 

Seems that at least NOBRACKET is gone from inlinepatterns. From the code in figureAltCaption I gather that this is actually not used (also BRK is not used). Could we just remove that from the import-line?

ronligt avatar Dec 08 '18 15:12 ronligt

I think it works fine with the mods (also changed the makeExtension-part)!

Newbie-mode: how can I submit the changes with a pull request?

ronligt avatar Dec 08 '18 16:12 ronligt

I think this is the documentation page which explains pull requesting. It assumes that you have forked the repo.

jdittrich avatar Dec 08 '18 16:12 jdittrich

Hi. I wanted to let you know that I've updated this plugin to work with Python Markdown 3, using Inline Patterns instead of Block Processors. See the code here. I have only implemented the support for image links, not image references (which I why I don't directly create a PR), but this should make it easier to adapt for the latter I hope.

jdumas avatar Jun 02 '19 01:06 jdumas

We processed hundreds of article with the extension on Python 3.6 and it was running perfectly. Only recently we move our code (with an old version of the extension) onto Python 3.8 and that fails on this traceback - ImportError: cannot import name 'NOBRACKET' from 'markdown.inlinepatterns'. Since then we updated on your latest commit 2c867c0 and it seems to work fine. Appreciated thanks your efforts.

fw2048 avatar Mar 29 '20 09:03 fw2048