diff options
| -rw-r--r-- | blog_admin/views.py | 3 | ||||
| -rw-r--r-- | templates/blog_admin/edit_post.html | 8 | ||||
| -rw-r--r-- | templates/blog_admin/new_post.html | 8 |
3 files changed, 13 insertions, 6 deletions
diff --git a/blog_admin/views.py b/blog_admin/views.py index 8f63be54..ea708936 100644 --- a/blog_admin/views.py +++ b/blog_admin/views.py @@ -3,6 +3,7 @@ from users.models import UserProfile from django.contrib.auth.models import User from django.contrib import messages from blog.models import Post, Category, Tag +import re # Create your views here. @@ -43,6 +44,7 @@ def new_post(request): if request.method == 'POST': title = request.POST.get('title') body = request.POST.get('body') + body = re.sub(r'<p><br></p>', '', body) category = request.POST.get('category') tags = request.POST.get('tags') slug = request.POST.get('slug') @@ -75,6 +77,7 @@ def edit_post(request, slug): if request.method == 'POST': title = request.POST.get('title') body = request.POST.get('body') + body = re.sub(r'<p><br></p>', '', body) category = request.POST.get('category') tags = request.POST.get('tags') slug = request.POST.get('slug') diff --git a/templates/blog_admin/edit_post.html b/templates/blog_admin/edit_post.html index 09bba62c..c221917d 100644 --- a/templates/blog_admin/edit_post.html +++ b/templates/blog_admin/edit_post.html @@ -125,7 +125,7 @@ static create(value) { const node = super.create(value); if (typeof value === "string") { - node.innerHTML = "" + this.tex2svg(value) + ""; + node.innerHTML = "" + this.tex2svg(value) + ""; node.contentEditable = "false"; node.setAttribute("data-value", value); } @@ -152,7 +152,7 @@ static create(value) { const node = super.create(value); if (typeof value === "string") { - node.innerHTML = "" + this.tex2svg(value) + ""; + node.innerHTML = "" + this.tex2svg(value) + ""; node.contentEditable = "false"; node.setAttribute("data-value", value); } @@ -244,7 +244,9 @@ }); try { - const delta = quill.clipboard.convert(document.getElementById("body").value); + const value = document.getElementById("body").value; + const newValue = value.replace(/<p><br><\/p>/g, ""); + const delta = quill.clipboard.convert(value); quill.setContents(delta, "silent"); } catch (e) { console.log(e); diff --git a/templates/blog_admin/new_post.html b/templates/blog_admin/new_post.html index 8d05d7b9..807d9d9a 100644 --- a/templates/blog_admin/new_post.html +++ b/templates/blog_admin/new_post.html @@ -125,7 +125,7 @@ static create(value) { const node = super.create(value); if (typeof value === "string") { - node.innerHTML = "" + this.tex2svg(value) + ""; + node.innerHTML = "" + this.tex2svg(value) + ""; node.contentEditable = "false"; node.setAttribute("data-value", value); } @@ -152,7 +152,7 @@ static create(value) { const node = super.create(value); if (typeof value === "string") { - node.innerHTML = "" + this.tex2svg(value) + ""; + node.innerHTML = "" + this.tex2svg(value) + ""; node.contentEditable = "false"; node.setAttribute("data-value", value); } @@ -244,7 +244,9 @@ }); try { - const delta = quill.clipboard.convert(document.getElementById("body").value); + const value = document.getElementById("body").value; + const newValue = value.replace(/<p><br><\/p>/g, ""); + const delta = quill.clipboard.convert(value); quill.setContents(delta, "silent"); } catch (e) { console.log(e); |
