黄舟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?
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))