From b2c18e009367a68acf22e494ceb3ec8c4acffcb5 Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 20 Sep 2022 20:29:17 -0400 Subject: Fixed empty spaces around formula and blog article --- blog_admin/views.py | 3 +++ templates/blog_admin/edit_post.html | 8 +++++--- 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'


', '', 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'


', '', 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>/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>/g, ""); + const delta = quill.clipboard.convert(value); quill.setContents(delta, "silent"); } catch (e) { console.log(e); -- cgit v1.2.3