From 0e7745d22af8301d0d327978734ee77353aa63c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9A=8F=E4=BA=91?= <1106584286@qq.com> Date: Fri, 27 Nov 2020 11:16:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update=20requirements.txt.=20markdown?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E7=94=9F=E6=88=90=E6=91=98=E8=A6=81=EF=BC=88?= =?UTF-8?q?=E4=B8=8D=E5=B8=A6markdown=E6=A0=87=E8=AE=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4b031a0..3c7f29a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ loguru==0.4.1 djangorestframework==3.9.1 requests==2.24.0 whoosh==2.7.4 -django-haystack==3.0 \ No newline at end of file +django-haystack==3.0 +Markdown-3.3.3 \ No newline at end of file From 212695f108f1278183c731f2ea77b453e853e78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9A=8F=E4=BA=91?= <1106584286@qq.com> Date: Fri, 27 Nov 2020 11:30:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update=20app=5Fdoc/views.py.=20markdown?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E7=94=9F=E6=88=90=E6=91=98=E8=A6=81=EF=BC=88?= =?UTF-8?q?=E4=B8=8D=E5=B8=A6markdown=E6=A0=87=E8=AE=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_doc/views.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app_doc/views.py b/app_doc/views.py index 8a49c76..6bd359e 100644 --- a/app_doc/views.py +++ b/app_doc/views.py @@ -23,6 +23,8 @@ from app_admin.decorators import check_headers,allow_report_file import os.path import base64 import hashlib +from django.utils.html import strip_tags +import markdown # 替换前端传来的非法字符 @@ -31,6 +33,11 @@ def validateTitle(title): new_title = re.sub(rstr, "_", title) # 替换为下划线 return new_title +# markdown文本生成摘要(不带markdown标记) +def remove_markdown_tag(docs): + for doc in docs: + doc.pre_content = strip_tags(markdown.markdown(doc.pre_content)) + return; # 获取文集的文档目录 def get_pro_toc(pro_id): @@ -303,6 +310,8 @@ def project_index(request,pro_id): project = Project.objects.get(id=int(pro_id)) # 获取文集最新的5篇文档 new_docs = Doc.objects.filter(top_doc=pro_id,status=1).order_by('-modify_time')[:5] + # markdown文本生成摘要(不带markdown标记) + remove_markdown_tag(new_docs) # 获取文集的文档目录 toc_list,toc_cnt = get_pro_toc(pro_id) # toc_list,toc_cnt = ([],1000)