@@ -42,6 +42,14 @@ import TextBlot, { escapeText } from "quill/blots/text";
42
42
import { Delta , Op } from "quill/core" ;
43
43
import Editor from "quill/core/editor" ;
44
44
45
+ interface ListItem {
46
+ child : Blot ;
47
+ offset : number ;
48
+ length : number ;
49
+ indent : number ;
50
+ type : string ;
51
+ }
52
+
45
53
/**
46
54
* Rich Text's extended Quill Editor
47
55
* allowing us to override certain editor's function, such as: getHTML
@@ -110,25 +118,23 @@ function getExpectedType(type: string | undefined, indent: number): string {
110
118
/**
111
119
* Copy with modification from https://github.com/slab/quill/blob/main/packages/quill/src/core/editor.ts
112
120
*/
113
- function convertListHTML ( items : any [ ] , lastIndent : number , types : string [ ] ) : string {
121
+ function convertListHTML ( items : ListItem [ ] , lastIndent : number , types : string [ ] ) : string {
114
122
if ( items . length === 0 ) {
115
123
const [ endTag ] = getListType ( types . pop ( ) ) ;
116
124
if ( lastIndent <= 0 ) {
117
- // modified by web-content: adding new line \n
118
- return `</li></${ endTag } >\n` ;
125
+ return `</li></${ endTag } >` ;
119
126
}
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 ) } ` ;
122
128
}
123
129
const [ { child, offset, length, indent, type } , ...rest ] = items ;
124
130
const [ tag , attribute ] = getListType ( type ) ;
125
- // modified by web-content: get proper list-style-type
126
- const expectedType = getExpectedType ( type , indent ) ;
131
+
127
132
if ( indent > lastIndent ) {
133
+ // modified by web-content: get proper list-style-type
134
+ const expectedType = getExpectedType ( type , indent ) ;
128
135
types . push ( type ) ;
129
136
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 (
132
138
child ,
133
139
offset ,
134
140
length
@@ -138,12 +144,10 @@ function convertListHTML(items: any[], lastIndent: number, types: string[]): str
138
144
}
139
145
const previousType = types [ types . length - 1 ] ;
140
146
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 ) } ` ;
143
148
}
144
149
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 ) } ` ;
147
151
}
148
152
149
153
/**
@@ -156,7 +160,8 @@ function convertHTML(blot: Blot, index: number, length: number, isRoot = false):
156
160
return blot . html ( index , length ) ;
157
161
}
158
162
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 ( " " , " " ) ;
160
165
}
161
166
if ( blot instanceof ParentBlot ) {
162
167
// TODO fix API
0 commit comments