malcommac / SwiftRichString

👩‍🎨 Elegant Attributed String composition in Swift sauce
MIT License
3.1k stars 211 forks source link

XMLStringBuilderError Failed to generate attributed string iOS Swift #120

Closed ahsanaasim closed 4 years ago

ahsanaasim commented 4 years ago

We are facing broken texts in our iOS app while creating AttributedTexts. The think is our string is a HTML string with custom tags and attributes.

Our app is live and texts are very sensitive. So we hope we will get a response soon. Thanks in advance...

Getting the following error:

Failed to generate attributed string from xml: XMLStringBuilderError(parserError: Error Domain=NSXMLParserErrorDomain Code=111 "(null)", line: 1, column: 152)

The string that is failing and causing the error is the string below no3 oie_transparent

This is the string: \u0623\u064e\u0645\u0652 \u064a\u064e\u0642\u064f\u0648\u0644\u064f\u0648\u0646\u064e <tajweed class=\"ham_wasl\" data-type=\"hamza-wasl\" data-description=\"Hamzat ul Wasl\" data-tajweed=\":6061\">\u0671<\/tajweed>\u0641\u0652\u062a\u064e\u0631\u064e\">\u066e\u0670<\/tajweed>\u0647\u064f\u200c\u06da \u0628\u064e\u0644\u0652 \u0647\u064f\u0648\u064e <tajweed class=\"ham_wasl\" data-type=\"hamza-wasl\" data-description=\"Hamzat ul Wasl\" data-tajweed=\":8923\">\u0671<\/tajweed>\u0644\u0652\u062d\u064e\u0642\u0651\u064f \u0645<tajweed class=\"idgh_w_ghn\" data-type=\"idgham-without-ghunnah\" data-description=\"Idgham - Without Ghunnah\" data-tajweed=\":770\">\u0650\u0646 \u0631<\/tajweed>\u0651\u064e\u0628\u0651\u0650\u0643\u064e \u0644\u0650\u062a\u064f<tajweed class=\"ikhf\" data-type=\"ikhafa\" data-description=\"Ikhafa'\" data-tajweed=\":4582\">\u0646\u0630<\/tajweed>\u0650\u0631\u064e \u0642\u064e\u0648\u0652<tajweed class=\"idgh_ghn\" data-type=\"idgham-with-ghunnah\" data-description=\"Idgham - With Ghunnah\" data-tajweed=\":10181\">\u0645\u064b\u0627 \u0645<\/tajweed>\u0651<tajweed class=\"madda_pbligatory\" data-type=\"madda-obligatory\" data-description=\"Obligatory Prolongation: 4-5 Vowels\" data-tajweed=\"\">\u064e\u0627\u0653<\/tajweed> \u0623\u064e\u062a\u064e<tajweed class=\"madda_normal\" data-type=\"madda-normal\" data-description=\"Normal Prolongation: 2 Vowels\" data-tajweed=\"\">\u0640\u0670<\/tajweed>\u0647<tajweed class=\"idghm_shfw\" data-type=\"idgham-shafawi\" data-description=\"Idgham Shafawi - With Meem\" data-tajweed=\":10182\">\u064f\u0645 \u0645<\/tajweed>\u0651<tajweed class=\"idgh_ghn\" data-type=\"idgham-with-ghunnah\" data-description=\"Idgham - With Ghunnah\" data-tajweed=\":10183\">\u0650\u0646 \u0646<\/tajweed>\u0651\u064e\u0630\u0650\u064a<tajweed class=\"idgh_ghn\" data-type=\"idgham-with-ghunnah\" data-description=\"Idgham - With Ghunnah\" data-tajweed=\":10184\">\u0631\u064d \u0645<\/tajweed>\u0651\u0650<tajweed class=\"ikhf\" data-type=\"ikhafa\" data-description=\"Ikhafa'\" data-tajweed=\":18\">\u0646 \u0642<\/tajweed>\u064e<tajweed class=\"qlq\" data-type=\"qalaqah\" data-description=\"Qalaqah\" data-tajweed=\":19\">\u0628\u0652<\/tajweed>\u0644\u0650\u0643\u064e \u0644\u064e\u0639\u064e\u0644\u0651\u064e\u0647\u064f\u0645\u0652 \u064a\u064e\u0647\u0652\u062a\u064e\u062f<tajweed class=\"madda_permissible\" data-type=\"madda-permissible\" data-description=\"Permissible Prolongation: 2, 4, 6 Vowels\" data-tajweed=\"\">\u064f\u0648<\/tajweed>\u0646\u064e\n

The output we are getting: asd

Our codes:

let c = ayah.text.replace(target: "\n", withString: "").set(style: getTazweedStyle())

func getTazweedStyle() -> StyleXML {
        let style = Style {
            $0.font = self.getFont() 
            $0.color = Colors.primaryTextColor
            $0.alignment = .right
            $0.lineSpacing = 4
            $0.lineBreakMode = .byWordWrapping
        }

        let groupStyle = StyleXML.init(base: style)

        return groupStyle
    }