Skip to content

Commit

Permalink
Update stringFromHtml method to handle replacing html tags that can't…
Browse files Browse the repository at this point in the history
… be stripped directly
  • Loading branch information
mazevedofs committed Aug 1, 2024
1 parent 0d88543 commit 75a9806
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Components/Sources/Components/Utility/HTMLUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,15 @@ public struct HtmlUtils {
}
}


public static func stringFromHTML(_ string: String) throws -> String {
let regex = try htmlTagRegex()
let cleanString = regex.stringByReplacingMatches(in: string, options: [], range: string.fullNSRange, withTemplate: "").replacingOccurrences(of: "&", with: "&")
return cleanString
let cleanString = regex.stringByReplacingMatches(in: string, options: [], range: string.fullNSRange, withTemplate: "")
let entityReplaceData = try entityReplaceData(html: cleanString)
let mutableCleanString = NSMutableString(string: cleanString)
for data in entityReplaceData {
mutableCleanString.replaceCharacters(in: data.range, with: data.replaceText)
}
return mutableCleanString as String
}

// MARK: - Shared - Private
Expand Down

0 comments on commit 75a9806

Please sign in to comment.