@@ -42,6 +42,14 @@ import TextBlot, { escapeText } from "quill/blots/text";
4242import { Delta , Op } from "quill/core" ;
4343import 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 ( " " , " " ) ;
160165 }
161166 if ( blot instanceof ParentBlot ) {
162167 // TODO fix API
0 commit comments