SwiftRichString icon indicating copy to clipboard operation
SwiftRichString copied to clipboard

Question: Handling multiple/nested tags

Open marcusway opened this issue 5 years ago • 0 comments

Hello!

  1. Thanks for this library; it's great.
  2. I'm wondering what the best way is for dealing with with nested tags. for instance, if i have <strong><em>Hello!</em></strong>, I'd like for "Hello!" to be both bolded and italicized, but the most deeply nested tag wins the day with my current approach (i.e. the hello example is italicized but not bolded). This is what I have:
let baseStyle = Style {...}

let boldStyle = baseStyle.byAdding {
    $0.traitVariants = $0.traitVariants?.union(.bold) ?? .bold;
    // have also tried $0.traitVariants = .bold, same effect
}

let italicStyle = baseStyle.byAdding {
    $0.traitVariants = $0.traitVariants?.union(.italic) ?? .italic
    // have also tried $0.traitVariants = .italic, same effect

}

let xmlStyle = SyleXML(base: baseStyle, ["strong": strongStyle, "em": italicStyle])

I'm a bit of an iOS noob; any direction here is much appreciated.

Thanks again!

marcusway avatar Jul 26 '20 13:07 marcusway