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

Commit

Permalink
fix: stopping replacing U200B by U200D character to stop freezing (#220)
Browse files Browse the repository at this point in the history
* fix: stopping replacing U200B by U200D character in order to stop freezing

* changing test
  • Loading branch information
maicon-brauwers authored Feb 8, 2022
1 parent 318c298 commit 0b3c93e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
1 change: 1 addition & 0 deletions Example/Source/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ViewController: UIViewController {
private enum Views {
static let subviews: [UIView] = [
InputOutputModuleView(text: "Here is some LaTeX: [math]x^n[/math]"),
InputOutputModuleView(text: "<html><p>&nbsp; 1. Testing non zero width spaces<br> ​  2. Some additional content here.</p></html>"),
InputOutputModuleView(text: "# Here is some Markdown:\n`Wow this is great!`"),
InputOutputModuleView(text: "Here is a YouTube video: youtube[DLzxrzFCyOs]"),
InputOutputModuleView(text: "<html><p>Here is some HTML</p></html>"),
Expand Down
6 changes: 1 addition & 5 deletions Source/Extensions/StringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
//

extension String {
func replaceAppropiateZeroWidthSpaces() -> String? {
let newString = self
let cleanString = 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: 1 addition & 2 deletions Source/Text Parsing/RichTextParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ class RichTextParser {
let inputStringWithoutBreakingSpaces = inputString.replaceTrailingWhiteSpaceWithNonBreakingSpace().replaceLeadingWhiteSpaceWithNonBreakingSpace()
let inputStringWithoutCommonEditorTags = self.removeCommonEditorTags(from: inputStringWithoutBreakingSpaces)
guard let inputAsHTMLString = try? Down(markdownString: inputStringWithoutCommonEditorTags).toHTML([.unsafe, .hardBreaks]),
let inputAsHTMLWithZeroWidthSpaceRemoved = inputAsHTMLString.replaceAppropiateZeroWidthSpaces(),
let htmlData = unescapeHTML(from: inputAsHTMLWithZeroWidthSpaceRemoved).data(using: .utf8) else {
let htmlData = unescapeHTML(from: inputAsHTMLString).data(using: .utf8) else {
return (mutableAttributedString.trimmingTrailingNewlinesAndWhitespaces(), [ParsingError.attributedTextGeneration(text: inputString)])
}
let parsedAttributedString = self.getParsedHTMLAttributedString(fromData: htmlData)
Expand Down

0 comments on commit 0b3c93e

Please sign in to comment.