Home  >  Q&A  >  body text

python - flask中markdowm提交文章图片显示不了

PHP中文网PHP中文网2741 days ago207

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:05:39

    allowed_tage Images without img have been filtered out

    reply
    0
  • 黄舟

    黄舟2017-04-18 10:05:39

    Have you solved the problem? After I used CKEditor to submit, the pictures were gone. Also, I would like to ask, how did you implement it in your editor?

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:05:39

    The picture is not displayed because the img stored in the database does not have the src attribute. You need to tell markdown which attributes you need to retain

        @staticmethod
        def on_changed_body(target, value, oldvalue, initiator):
            allowed_tage = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code',
                            'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul',
                            'h1', 'h2', 'h3', 'p', 'img']
            attrs = {
                'img': ['src', 'alt']
            }
            target.body_html = bleach.linkify(bleach.clean(markdown(value, output_format='html'), tags=allowed_tage, attributes=attrs, strip=True))

    reply
    0
  • Cancelreply