Skip to content

Commit

Permalink
输入的正文有特殊符号时,转义
Browse files Browse the repository at this point in the history
  • Loading branch information
rztime committed Jan 24, 2024
1 parent da0ed34 commit 2242a57
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion RZRichTextView/Classes/RZHtml.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public extension NSAttributedString {
if let attachment = dict[.attachment] as? NSTextAttachment {
labelStar.append(attachment.rz2html)
} else if tempAttr.string.count > 0 {
let text = tempAttr.string.replacingOccurrences(of: "\n", with: "")
let text = tempAttr.string.replacingOccurrences(of: "\n", with: "").fixHtml()
labelStar.append(text)
}
let temp = labelStar + labelEnd
Expand Down Expand Up @@ -420,6 +420,22 @@ public extension String {
}
return tempAttr.rt.trimmingCharacters(in: options.trimingCharacters)
}
func fixHtml() -> String {
let symbols = [
("&", "&"),
("<","&lt;"),
(">","&gt;"),
(" ","&nbsp;"),
("©","&copy;"),
("®","&trade;"),
("","&nbsp;"),
]
var temp = self
symbols.forEach { (v1, v2) in
temp = temp.replacingOccurrences(of: v1, with: v2)
}
return temp
}
}

public extension UIImage {
Expand Down

0 comments on commit 2242a57

Please sign in to comment.