@@ -12,6 +12,7 @@ import BonMot
1212public final class VEditorXMLBuilder {
1313
1414 public static let shared : VEditorXMLBuilder = . init( )
15+ public var encodingHTMLEntitiesExternalHandler : ( ( String ) -> String ) ?
1516
1617 public func buildXML( _ contents: [ VEditorContent ] ,
1718 rule: VEditorRule ,
@@ -73,8 +74,7 @@ public final class VEditorXMLBuilder {
7374 using: { attributes, subRange, _ in
7475
7576 var content = attrText. attributedSubstring ( from: subRange) . string
76- content = content
77- . replacingOccurrences ( of: " \" " , with: " \\ " )
77+ content = content. encodingHTMLEntities ( )
7878
7979 guard !content. isEmpty else { return }
8080
@@ -148,4 +148,26 @@ extension String {
148148 }
149149 return xmlString
150150 }
151+
152+ internal func encodingHTMLEntities( ) -> String {
153+ guard let handler = VEditorXMLBuilder . shared. encodingHTMLEntitiesExternalHandler else {
154+ // NOTE: default encoding HTML Entities for VEditor
155+ // ref: https://dev.w3.org/html5/html-author/charref
156+ return self . replacingOccurrences ( of: " & " , with: " & " )
157+ . replacingOccurrences ( of: " < " , with: " < " )
158+ . replacingOccurrences ( of: " > " , with: " > " )
159+ . replacingOccurrences ( of: " \" " , with: " " " )
160+ . replacingOccurrences ( of: " ' " , with: " ' " )
161+ . replacingOccurrences ( of: " ' " , with: " 9 " )
162+ . replacingOccurrences ( of: " ' " , with: " ’ " )
163+ . replacingOccurrences ( of: " ' " , with: " – " )
164+ }
165+
166+ return handler ( self )
167+ }
168+
169+ internal func convertDuplicatedBackSlashToValidParserXML( ) -> String {
170+ return self . replacingOccurrences ( of: " \\ n " , with: " \n " )
171+ . replacingOccurrences ( of: " \\ " , with: " " )
172+ }
151173}
0 commit comments