Skip to content

Commit 6284fff

Browse files
committed
评论markdown优化
1 parent d47169b commit 6284fff

File tree

6 files changed

+11
-17
lines changed

6 files changed

+11
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ google93fd32dbd906620a.html
7474
baidu_verify_FlHL7cUyC9.html
7575
BingSiteAuth.xml
7676
cb9339dbe2ff86a5aa169d28dba5f615.txt
77-
werobot_session
77+
werobot_session.*
7878
django.jpg
7979
uploads/
8080
settings_production.py

blog/templatetags/blog_tags.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import random
44
import urllib
55

6+
import bleach
67
from django import template
78
from django.conf import settings
89
from django.db.models import Q
@@ -13,6 +14,7 @@
1314

1415
from blog.models import Article, Category, Tag, Links, SideBar, LinkShowType
1516
from comments.models import Comment
17+
from djangoblog.utils import CommonMarkdown
1618
from djangoblog.utils import cache
1719
from djangoblog.utils import get_current_site
1820
from oauth.models import OAuthUser
@@ -40,10 +42,10 @@ def datetimeformat(data):
4042
return ""
4143

4244

43-
@register.filter(is_safe=True)
45+
@register.filter()
4446
@stringfilter
4547
def custom_markdown(content):
46-
from djangoblog.utils import CommonMarkdown
48+
content = bleach.clean(content)
4749
return mark_safe(CommonMarkdown.get_markdown(content))
4850

4951

@@ -258,16 +260,6 @@ def load_pagination_info(page_obj, page_type, tag_name):
258260
}
259261

260262

261-
"""
262-
@register.inclusion_tag('nav.html')
263-
def load_nav_info():
264-
category_list = Category.objects.all()
265-
return {
266-
'nav_category_list': category_list
267-
}
268-
"""
269-
270-
271263
@register.inclusion_tag('blog/tags/article_info.html')
272264
def load_article_detail(article, isindex, user):
273265
"""

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
coverage==6.1.2
2+
bleach==4.1.0
23
Django==3.2.9
34
django-compressor==2.4.1
45
django-haystack==3.1.1

templates/blog/tags/sidebar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<aside class="widget_text widget widget_custom_html"><p class="widget-title">
1616
{{ sidebar.name }}</p>
1717
<div class="textwidget custom-html-widget">
18-
{{ sidebar.content|custom_markdown }}
18+
{{ sidebar.content|custom_markdown|safe }}
1919
</div>
2020
</aside>
2121
{% endfor %}

templates/comments/tags/comment_item.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
<div>{{ comment_item.created_time }}</div>
2525
<div>回复给:@{{ comment_item.author.parent_comment.username }}</div>
2626
</div>
27-
28-
<p>{{ comment_item.body |custom_markdown }}</p>
29-
27+
{% autoescape on %}
28+
<p>{{ comment_item.body|custom_markdown }}</p>
29+
{% endautoescape %}
3030
<div class="reply"><a rel="nofollow" class="comment-reply-link"
3131
href="javascript:void(0)"
3232
onclick="do_reply({{ comment_item.pk }})"

templates/comments/tags/comment_item_tree.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
</div>
3232
{% endif %}
3333
</p>
34+
3435
<p>{{ comment_item.body|custom_markdown }}</p>
3536

3637
<div class="reply"><a rel="nofollow" class="comment-reply-link"

0 commit comments

Comments
 (0)