CTRubyAnnotation + AttributedString
- Foundation/SwiftUI/UIKit/CoreText forgot to add
kCTRubyAnnotationAttributeNametoAttributedString(FB9953514) - SwiftUI
Textignores custom attributes UITextViewdoesn't work because reasons
Note: remember adding
including: \.coreTextwhen constructingNSAttributedStringor else it will ignore custom attributes as well.
Construct AttributedString directly:
var attributes = AttributeContainer()
attributes.rubyAnnotation = .makeRubyAnnotation(text: [.before: "ねこ"])
let attributedString = AttributedString("猫", attributes: attributes)... or from markdown:
// defaults to before
try AttributedString(
markdown: "^[猫](CTRubyAnnotation: 'ねこ')",
including: \.coreText,
options: .init(allowsExtendedAttributes: true)
)
// but you can specify where exactly, or even multiple positions
AttributedString(localized:
"""
The ^[猫](CTRubyAnnotation: {interCharacter: 'ㄇㄠ', after: 'cat'}) \
is seeking adoption.
""", including: \.coreText)