【发布时间】:2019-05-22 15:41:14
【问题描述】:
我在我的 Django 网站中创建了一个 Markdown 过滤器。我使用了库markdown2。
虽然 HTML 会呈现,但它不会完全呈现它。 代码和语法亮点、URL 和列表无法正确呈现。
模板标签文件夹
文件名:ttags.py
from django.template import Library
import markdown2
register = Library()
@register.filter('markdown_to_html')
def markdown_to_html(markdown_text):
htmlversion=markdown2.markdown(markdown_text)
return htmlversion
模板文件
{% extends "layout.html" %}
{% load ttags %}
{% load static from staticfiles %}
{% block content %}
<div class="content">
{{ step.description | markdown_to_html | safe }}
</div>
{% endblock %}
提供的要渲染的文本如下
##### Usage of Variables
```python
name = "David"
age = 10
```
In the above example name and age are variables that store Text and Numbers respectively.
> Always remember to use Variables in your programs to store information.
渲染输出的 HTML 代码如下
<h5>Usage of Variables</h5>
<p><code>python
name = "David"
age = 10
</code></p>
<p>In the above example name and age are variables that store Text and Numbers respectively.</p>
<blockquote>
<p>Always remember to use Variables in your programs to store information.</p>
</blockquote>
代码语法不显示在两行中
【问题讨论】:
-
Blockquote 已解决。代码块没有出现在两行中。
-
请使用呈现的 HTML 代码更新您的问题,而不是屏幕截图。您可能需要使用浏览器的“查看源代码”或“检查”工具来获取 HTML。
-
<code> name='David' print(name) </code> -
请edit 将您的问题粘贴到为整个 Markdown 输入呈现的 HTML 中。
-
问题已编辑
标签: django markdown django-template-filters