chrisdhaan / CDMarkdownKit

An extensive Swift framework providing simple and customizable markdown parsing.
MIT License
254 stars 66 forks source link

Add custom attribute #19

Open DingSoung opened 5 years ago

DingSoung commented 5 years ago

for example

            let detailLocation = gesture.location(in: contentLabel)
            let storage = NSTextStorage(attributedString: contentLabel.attributedText)
            let manager = NSLayoutManager()
            storage.addLayoutManager(manager)
            let container = NSTextContainer(size: CGSize(width: contentLabel.bounds.size.width, height: CGFloat.greatestFiniteMagnitude))
            container.lineFragmentPadding = 0
            container.maximumNumberOfLines = contentLabel.numberOfLines
            container.lineBreakMode = contentLabel.lineBreakMode
            manager.addTextContainer(container)
            let index = manager.characterIndex(for: detailLocation, in: container, fractionOfDistanceBetweenInsertionPoints: nil)
            let attributes = attributedText.attributes(at: index, effectiveRange: nil)
            if let attrbuteValue = attributes[CustomAttributedKey] as? String {
                 print("url is ", attrbuteValue)
            }

and other type, at(@xxx) image preview etc.

custome attrbutes interface is needed

chrisdhaan commented 3 years ago

I'm not quite sure I understand what you want in a custom attributes interface. Could you give me a more detailed description of what you are showing me in that example @DingSoung