Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
fix: replace zero width spaces with appropriate ones (#138)
Browse files Browse the repository at this point in the history
* Version Bump

* Merge branch 'master' of https://github.com/tophat/RichTextView

* Update StringExtension.swift
  • Loading branch information
BisuGit authored Feb 18, 2020
1 parent b557c92 commit 52b87e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Source/Extensions/StringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
//

extension String {
func replaceAppropiateZeroWidthSpaces() -> String? {
var newString = self
let cleanString = try? newString.replacingOccurrences(of: "\u{200B}", with: "\u{200D}")
return cleanString
}
func replaceTrailingWhiteSpaceWithNonBreakingSpace() -> String {
var newString = self
while newString.last?.isWhitespace == true {
Expand Down
3 changes: 2 additions & 1 deletion Source/Text Parsing/RichTextParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class RichTextParser {
]
let cleanRelevantString = relevantString.replaceTrailingWhiteSpaceWithNonBreakingSpace().replaceLeadingWhiteSpaceWithNonBreakingSpace()
guard let inputAsHTMLString = try? Down(markdownString: cleanRelevantString).toHTML([.unsafe, .hardBreaks]),
let htmlData = inputAsHTMLString.data(using: .utf8) else {
let inputAsHTMLStringWithZeroWidthSpaceRemoved = inputAsHTMLString.replaceAppropiateZeroWidthSpaces(),
let htmlData = inputAsHTMLStringWithZeroWidthSpaceRemoved.data(using: .utf8) else {
return (nil, ParsingError.attributedTextGeneration(text: relevantString))
}
var attributedString: NSAttributedString?
Expand Down

0 comments on commit 52b87e3

Please sign in to comment.