Skip to content

Commit e5fbddb

Browse files
committed
fix: rich text formatting
1 parent 366b86e commit e5fbddb

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

packages/pluggableWidgets/rich-text-web/src/utils/MxQuill.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ import TextBlot, { escapeText } from "quill/blots/text";
4242
import { Delta, Op } from "quill/core";
4343
import Editor from "quill/core/editor";
4444

45+
interface ListItem {
46+
child: Blot;
47+
offset: number;
48+
length: number;
49+
indent: number;
50+
type: string;
51+
}
52+
4553
/**
4654
* Rich Text's extended Quill Editor
4755
* allowing us to override certain editor's function, such as: getHTML
@@ -110,25 +118,23 @@ function getExpectedType(type: string | undefined, indent: number): string {
110118
/**
111119
* Copy with modification from https://github.com/slab/quill/blob/main/packages/quill/src/core/editor.ts
112120
*/
113-
function convertListHTML(items: any[], lastIndent: number, types: string[]): string {
121+
function convertListHTML(items: ListItem[], lastIndent: number, types: string[]): string {
114122
if (items.length === 0) {
115123
const [endTag] = getListType(types.pop());
116124
if (lastIndent <= 0) {
117-
// modified by web-content: adding new line \n
118-
return `</li></${endTag}>\n`;
125+
return `</li></${endTag}>`;
119126
}
120-
// modified by web-content: adding new line \n
121-
return `</li></${endTag}>\n${convertListHTML([], lastIndent - 1, types)}`;
127+
return `</li></${endTag}>${convertListHTML([], lastIndent - 1, types)}`;
122128
}
123129
const [{ child, offset, length, indent, type }, ...rest] = items;
124130
const [tag, attribute] = getListType(type);
125-
// modified by web-content: get proper list-style-type
126-
const expectedType = getExpectedType(type, indent);
131+
127132
if (indent > lastIndent) {
133+
// modified by web-content: get proper list-style-type
134+
const expectedType = getExpectedType(type, indent);
128135
types.push(type);
129136
if (indent === lastIndent + 1) {
130-
// modified by web-content: adding list-style-type to allow retaining list style when converted to html and new line \n
131-
return `<${tag} style="list-style-type: ${expectedType}">\n<li${attribute}>${convertHTML(
137+
return `<${tag} style="list-style-type: ${expectedType}"><li${attribute}>${convertHTML(
132138
child,
133139
offset,
134140
length
@@ -138,12 +144,10 @@ function convertListHTML(items: any[], lastIndent: number, types: string[]): str
138144
}
139145
const previousType = types[types.length - 1];
140146
if (indent === lastIndent && type === previousType) {
141-
// modified by web-content: adding new line \n
142-
return `</li>\n<li${attribute}>${convertHTML(child, offset, length)}${convertListHTML(rest, indent, types)}`;
147+
return `</li><li${attribute}>${convertHTML(child, offset, length)}${convertListHTML(rest, indent, types)}`;
143148
}
144149
const [endTag] = getListType(types.pop());
145-
// modified by web-content: adding new line \n
146-
return `</li></${endTag}>\n${convertListHTML(items, lastIndent - 1, types)}`;
150+
return `</li></${endTag}>${convertListHTML(items, lastIndent - 1, types)}`;
147151
}
148152

149153
/**
@@ -156,7 +160,8 @@ function convertHTML(blot: Blot, index: number, length: number, isRoot = false):
156160
return blot.html(index, length);
157161
}
158162
if (blot instanceof TextBlot) {
159-
return escapeText(blot.value().slice(index, index + length));
163+
const escapedText = escapeText(blot.value().slice(index, index + length));
164+
return escapedText.replaceAll(" ", "&nbsp;");
160165
}
161166
if (blot instanceof ParentBlot) {
162167
// TODO fix API

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/assets/css/quill-table-better.scss

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ $focused-border: 1px solid $focused-border-color;
3131
left: 50%;
3232
bottom: -10px;
3333
transform: translate(-50%, 100%);
34+
3435
&::before {
3536
@extend .ql-table-triangle-common;
3637
border-bottom-color: $color !important;
3738
top: -20px;
3839
}
40+
3941
&:hover {
4042
display: block;
4143
}
44+
4245
&-hidden {
4346
display: none !important;
4447
}
@@ -50,6 +53,7 @@ $focused-border: 1px solid $focused-border-color;
5053
#{$direction1}: -20px;
5154
border-#{$direction2}-color: $color1 !important;
5255
}
56+
5357
&:not(.ql-table-triangle-none)::after {
5458
@extend .ql-table-triangle-common;
5559
#{$direction1}: -19px;
@@ -299,6 +303,7 @@ $focused-border: 1px solid $focused-border-color;
299303
line-height: 30px;
300304
list-style: none;
301305
padding-left: 10px;
306+
302307
&:hover {
303308
background-color: $hover-background;
304309
}
@@ -521,8 +526,11 @@ $focused-border: 1px solid $focused-border-color;
521526

522527
&-error {
523528
@include qlTableTooltip($tooltip-color-error);
524-
white-space: pre-wrap;
525-
z-index: 9;
529+
530+
& {
531+
white-space: pre-wrap;
532+
z-index: 9;
533+
}
526534
}
527535
}
528536

@@ -559,6 +567,7 @@ $focused-border: 1px solid $focused-border-color;
559567
z-index: 10;
560568
border: 1px solid #979797;
561569
cursor: nwse-resize;
570+
562571
&-move {
563572
cursor: crosshair;
564573
border: none;
@@ -574,6 +583,7 @@ $focused-border: 1px solid $focused-border-color;
574583
position: absolute;
575584
z-index: 10;
576585
@extend .ql-table-center;
586+
577587
.ql-operate-line {
578588
background-color: $line-color;
579589
}
@@ -653,12 +663,15 @@ ol.table-list-container {
653663
20% {
654664
transform: translateX(-2px);
655665
}
666+
656667
40% {
657668
transform: translateX(2px);
658669
}
670+
659671
60% {
660672
transform: translateX(-1px);
661673
}
674+
662675
80% {
663676
transform: translateX(1px);
664677
}

0 commit comments

Comments
 (0)