dcolish / flask-markdown

Markdown jinja2 extension for Flask
Other
199 stars 45 forks source link

ImportError: cannot import name 'Markup' from 'flask' #25

Open glopglopoups opened 1 year ago

glopglopoups commented 1 year ago

Hello,

Following the evolution of Flask, an error appears on the "flask-markdown" module.

Would it be possible to fix the module to fit Flask 3.x. x?

Thank you for your help,

dcolish commented 1 year ago

If you can propose a fix I'm happy to review and approve. I stepped away from this project a long time ago after it was rejected for listing with approved flask plug-ins and left the code for the community.

If it's valuable I'd love to transfer ownership. I'll share an announcement in the readme and in an issue that it will be archived by end of year if no one has time to take it.

Thanks Dan

SSAdvisor commented 11 months ago

How about something like:

try:
    from flask import Markup
except:
    try:
         from markupsafe import Markup
    except:
         raise Exception('Markup module not found')
SSAdvisor commented 11 months ago

Here is what worked for me:

diff --git a/flaskext/markdown.py b/flaskext/markdown.py
index 0059852..413c2fd 100644
--- a/flaskext/markdown.py
+++ b/flaskext/markdown.py
@@ -29,8 +29,15 @@ decorating the extension class with :func:`extend`
 :license: BSD, MIT see LICENSE for more details.
 """
 from __future__ import absolute_import
-from flask import Markup
-from jinja2 import evalcontextfilter, escape
+try:
+    from flask import Markup
+except:
+    from markupsafe import Markup
+try:
+    from jinja2 import evalcontextfilter, escape
+except:
+    from jinja2 import pass_eval_context as evalcontextfilter
+    from markupsafe import escape
 import markdown as md
 from markdown import (
     blockprocessors,
vanzhiganov commented 10 months ago

@dcolish PR https://github.com/dcolish/flask-markdown/pull/26 based on diff from @SSAdvisor