Skip to content

Commit 84c8bb4

Browse files
committed
fix: remove style attributes from produced HTML to prevent force colorign in black. Add basic typography margins
1 parent 9c5f195 commit 84c8bb4

File tree

1 file changed

+80
-4
lines changed

1 file changed

+80
-4
lines changed

custom/quillEditor.vue

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import AsyncQueue from './async-queue';
2727
import Quill from "quill";
2828
import "quill/dist/quill.snow.css";
2929
30-
3130
function dbg(title: string,...args: any[]) {
3231
// return; // comment for debug
3332
console.log(title, ...args.map(a =>JSON.stringify(a, null, 1)));
@@ -292,7 +291,16 @@ onMounted(() => {
292291
async function emitTextUpdate() {
293292
const editorHtml = quill.root.innerHTML;
294293
// remove completion from html
295-
const html = editorHtml.replace(/<span[^>]*completer[^>]*>.*?<\/span>/g, '');
294+
let html = editorHtml.replace(/<span[^>]*completer[^>]*>.*?<\/span>/g, '');
295+
296+
// remove all style attributes
297+
const parser = new DOMParser();
298+
const doc = parser.parseFromString(html, 'text/html');
299+
const elements = doc.querySelectorAll('*');
300+
elements.forEach((el) => {
301+
el.removeAttribute('style');
302+
});
303+
html = doc.body.innerHTML;
296304
297305
if (lastText === html) {
298306
return;
@@ -527,8 +535,76 @@ function removeCompletionOnBlur() {
527535
font-style: italic;
528536
}
529537
530-
.ql-editor p {
531-
margin-bottom: 0.5rem;
538+
// basic typography
539+
.ql-editor {
540+
line-height: 1.5;
541+
542+
/* Headings */
543+
h1, h2, h3, h4, h5, h6 {
544+
margin-top: 0.5rem;
545+
margin-bottom: 0.25rem;
546+
}
547+
548+
/* Paragraphs */
549+
p {
550+
margin-bottom: 0.4rem;
551+
}
552+
553+
/* Lists */
554+
ul, ol {
555+
margin-top: 0.4rem;
556+
margin-bottom: 0.4rem;
557+
padding-left: 1rem;
558+
}
559+
560+
/* List items */
561+
li {
562+
margin-bottom: 0.2rem;
563+
}
564+
565+
/* Horizontal rule */
566+
hr {
567+
margin: 0.8rem 0;
568+
border: none;
569+
border-top: 1px solid #ddd;
570+
}
571+
572+
/* Blockquotes */
573+
blockquote {
574+
margin: 0.8rem 0;
575+
padding-left: 0.8rem;
576+
border-left: 2px solid #ccc;
577+
}
578+
579+
/* Preformatted text */
580+
pre {
581+
margin: 0.8rem 0;
582+
padding: 0.4rem;
583+
background: #f8f9fa;
584+
border-radius: 3px;
585+
}
586+
587+
/* Tables */
588+
table {
589+
margin: 0.8rem 0;
590+
border-collapse: collapse;
591+
}
592+
593+
th, td {
594+
padding: 0.3rem;
595+
border: 1px solid #ddd;
596+
}
597+
598+
thead th {
599+
border-bottom: 1.5px solid #aaa;
600+
}
601+
602+
/* Images */
603+
img {
604+
margin: 0.4rem 0;
605+
max-width: 100%;
606+
height: auto;
607+
}
532608
}
533609
534610
.ql-snow .ql-stroke {

0 commit comments

Comments
 (0)