Markdowned 内容未反映在我的 html 模板中 (<em><strong>)

问题描述 投票:0回答:1

在我的 Django 项目中,我使用 markdownify 将 markdown 转换为 HTML。 我在将 HTML 内容渲染到模板时遇到问题。

一些标签如

<em>
<strong>
没有得到反映。 我已尝试使用此stackoverflow帖子中建议的安全过滤器,但我发现没有任何变化!

我可以使用任何其他过滤器或任何方法来正确渲染

在settings.py中

MARKDOWNIFY = {
  "default": {
        "STRIP": True,
        "BLEACH": True,
        "MARKDOWNIFY_LINKIFY_TEXT": True,
        "WHITELIST_TAGS": [
            'a',
            'abbr',
            'acronym',
            'b',
            'blockquote',
            'em',
            'i',
            'li',
            'ol',
            'p',
            'strong',
            'ul'
        ],
        "WHITELIST_ATTRS": [
            'href',
            'src',
            'alt',
        ],
        "WHITELIST_STYLES": [
            'color',
            'font-weight',
        ],
        "LINKIFY_TEXT": {
            "PARSE_URLS": True,
            "PARSE_EMAIL": True,
            "CALLBACKS": [],
            "SKIP_TAGS": ['pre', 'code',],
        },
         "WHITELIST_PROTOCOLS": [
            'http',
            'https',
        ],
        "MARKDOWN_EXTENSIONS": [
            'markdown.extensions.fenced_code',
            'markdown.extensions.extra',
            
        ]
  },
}

在我的模板中:

<div class="col-8">
    {{ entry|markdownify|safe }}
</div>

内容:

#This is the H1 tag for Heading

but these are working

- paragraph

- all the headers

- list tag

things not getting converted

- *Italics not working*

- **And also bold text**

在我的模板中,这就是我得到的



This is the H1 tag for Heading
but these are working

paragraph

all the headers

list tag

things not getting converted

<em>Italics not working</em>

<strong>And also bold text</strong>

图片供参考:

  • content to be markdowned
  • final outcome that I got
html django cs50
1个回答
0
投票

将其添加到您的settings.py中,它应该可以正常工作。

MARKDOWNIFY_WHITELIST_TAGS = [
'a',
'abbr',
'acronym',
'b',
'blockquote',
'em',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'i',
'li',
'ol',
'p',
'strong',
'ul'
]
© www.soinside.com 2019 - 2024. All rights reserved.