Git Product home page Git Product logo

atributika's Introduction


🚨V5 is now released!🚨

Atributika is a Swift library that provides a simple way to build NSAttributedString from HTML-like text, by identifying and styling tags, links, phone numbers, hashtags etc.

A standalone AtributikaViews library offers UILabel/UITextView drop-in replacements capable of displaying highlightable and clickable links, with rich customization, and proper accessibility support.

Note

Try my new library for doing Auto Layout, a typesafe reimagination of Visual Format Language: https://github.com/psharanda/FixFlex

Intro

While NSAttributedString is undoubtedly powerful, it's also a low-level API that needs a considerable amount of setup work. If your string is a template and the actual content is only known at runtime, this becomes complicated. When dealing with localizations, constructing NSAttributedString isn't straightforward either.

But wait, Atributika comes to your rescue!

let b = Attrs().font(.boldSystemFont(ofSize: 20)).foregroundColor(.red)
        
label.attributedText = "Hello <b>World</b>!!!".style(tags: ["b": b]).attributedString

Indeed, that's much simpler. Atributika is easy-to-use, declarative, flexible, and handles the rough edges for you.

Features

Atributika

  • NSAttributedString builder.
  • Detects and styles HTML-like tags using a custom high-speed parser.
  • Detects and styles hashtags and mentions (i.e., #something and @someone).
  • Identifies and styles links and phone numbers.
  • Detects and styles regexes and NSDataDetector patterns.
  • Styles the entire string or just specified ranges.
  • Allows all the above to be chained together to parse complex strings!
  • Provides a clean and expressive API to construct styles.
  • Offers a separate set of detection utilities for standalone use.
  • Compatible with iOS, tvOS, watchOS, and macOS.

AtributikaViews

  • Custom views with highlightable and clickable links.
  • Custom text styles for normal/highlighted/disabled states.
  • Supports custom highlighting.

V5

V5 is a major rewrite of the project, executed in early 2023. It's not fully compatible with the previous version and requires some manual migration. The introduction of breaking changes was necessary for the project's further evolution.

Here's what's new:

NSAttributedString Building

  • Completely rewritten HTML parser, which fixed a multitude of bugs and improved handling of edge cases.
  • More generic and robust text transforming and attribute fine-tuning APIs.

AttributedLabel / AttributedTextView

  • Moved to a standalone library, independent of Atributika.
  • Offers proper accessibility support.
  • Improved performance and touch handling.
  • AttributedLabel is based on UILabel (lightweight, with vertically-centered text).
  • AttributedTextView is based on UITextView (supports scrolling and text selection, with text aligned to the top of the frame).

New examples have been added to the Demo application, including:

  • Basic web browser powered by AttributedTextView
  • SwiftUI integration
  • Highlightable links for Markdown documents

Examples

Detect and style tags, provide base style for the rest of string, don't forget about special html symbols

let redColor = UIColor(red:(0xD0 / 255.0), green: (0x02 / 255.0), blue:(0x1B / 255.0), alpha:1.0)
let a = Attrs().foregroundColor(redColor)

let font = UIFont(name: "AvenirNext-Regular", size: 24)!
let grayColor = UIColor(white: 0x66 / 255.0, alpha: 1)
let base = Attrs().font(font).foregroundColor(grayColor)

let str = "<a>&lt;a&gt;</a>tributik<a>&lt;/a&gt;</a>"
    .style(tags: ["a": a])
    .styleBase(base)
    .attributedString

Detect and style hashtags and mentions

let str = "#Hello @World!!!"
    .styleHashtags(Attrs().font(.boldSystemFont(ofSize: 45)))
    .styleMentions(Attrs().foregroundColor(.red))
    .attributedString

Detect and style links

let str = "Check this website http://google.com"
    .styleLinks(Attrs().foregroundColor(.blue))
    .attributedString

Detect and style phone numbers

let str = "Call me (888)555-5512"
    .stylePhoneNumbers(Attrs().foregroundColor(.red))
    .attributedString

Uber String

let links = Attrs().foregroundColor(.blue)
let phoneNumbers = Attrs().backgroundColor(.yellow)
let mentions = Attrs().font(.italicSystemFont(ofSize: 12)).foregroundColor(.black)
let b = Attrs().font(.boldSystemFont(ofSize: 12))
let u = Attrs().underlineStyle(.single)

let base = Attrs().font(.systemFont(ofSize: 12)).foregroundColor(.gray)

let str = "@all I found <u>really</u> nice framework to manage attributed strings. It is called <b>Atributika</b>. Call me if you want to know more (123)456-7890 #swift #nsattributedstring https://github.com/psharanda/Atributika"
    .style(tags: ["u": u, "b": b])
    .styleMentions(mentions)
    .styleHashtags(links)
    .styleLinks(links)
    .stylePhoneNumbers(phoneNumbers)
    .styleBase(base)
    .attributedString

AttributedLabel

let tweetLabel = AttributedLabel()

tweetLabel.numberOfLines = 0
tweetLabel.highlightedLinkAttributes = Attrs().foregroundColor(.red).attributes

let baseLinkAttrs = Attrs().foregroundColor(.blue)

let a = TagTuner {
    Attrs(baseLinkAttrs).akaLink($0.tag.attributes["href"] ?? "")
}

let hashtag = DetectionTuner {
    Attrs(baseLinkAttrs).akaLink("https://twitter.com/hashtag/\($0.text.replacingOccurrences(of: "#", with: ""))")
}

let mention = DetectionTuner {
    Attrs(baseLinkAttrs).akaLink("https://twitter.com/\($0.text.replacingOccurrences(of: "@", with: ""))")
}

let link = DetectionTuner {
    Attrs(baseLinkAttrs).akaLink($0.text)
}

let tweet = "@all I found <u>really</u> nice framework to manage attributed strings. It is called <b>Atributika</b>. Call me if you want to know more (123)456-7890 #swift #nsattributedstring https://github.com/psharanda/Atributika"

tweetLabel.attributedText = tweet
    .style(tags: ["a": a])
    .styleHashtags(hashtag)
    .styleMentions(mention)
    .styleLinks(link)
    .attributedString

tweetLabel.onLinkTouchUpInside = { _, val in
    if let linkStr = val as? String {
        if let url = URL(string: linkStr) {
            UIApplication.shared.openURL(url)
        }
    }
}

view.addSubview(tweetLabel)

Requirements

Current version is compatible with:

  • Swift 5.0+
  • iOS 11.0 or later
  • tvOS 11.0 or later
  • watchOS 4.0 or later
  • macOS 10.13 or later

Note: AttributedLabel / AttributedTextView are available only on iOS

Why does Atributika have one 't' in its name?

Because in Belarusian/Russian we have one letter 't' (атрыбутыка/атрибутика). So basically it is transcription, not a real word.

Integration

Add dependency to Package.swift file.

  dependencies: [
    .package(url: "https://github.com/psharanda/Atributika.git", .upToNextMajor(from: "5.0.0"))
  ]

Carthage

Add github "psharanda/Atributika" to your Cartfile

CocoaPods

Atributika is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Atributika"
pod "AtributikaViews"

Manual

  1. Add Atributika to you project as a submodule using git submodule add https://github.com/psharanda/Atributika.git
  2. Open the Atributika folder & drag Atributika.xcodeproj into your project tree
  3. Add Atributika.framework to your target's Link Binary with Libraries Build Phase
  4. Import Atributika with import Atributika and you're ready to go

License

Atributika is available under the MIT license. See the LICENSE file for more info.

atributika's People

Contributors

343max avatar civelxu avatar cuzv avatar danl3v avatar futuretap avatar graham-perks-snap avatar joseph2166 avatar petropavel13 avatar psharanda avatar rivera-ernesto avatar rushk2112 avatar samingle avatar vinayakparmar92 avatar zeveisenberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atributika's Issues

Tags at start of text apply throughout text.

Starting text with a tag applies that tag throughout, even though there is a matching end tag.

"Save $1.00 on any order!" comes out all bold.

"Save $1.00 on any order!" correctly bolds only the two sections.

With this call:

            let desc = Atributika(text: text,
                                  styles: [
                                    "b" : [.font( UIFont.boldSystemFont(ofSize: 14))]
                ],
                                  baseStyle: [
                                    .font( UIFont.systemFont(ofSize: 14)), .foregroundColor(UIColor.red)
                ])
                .buildAttributedString()

Style.swift Crash

Hi , Style.Swift line 84 and AttributedText.swift line 99 crash , swift 4.1 , Xcode 9 latest version , ios 11 ,
just copy pasted your "link" and "all" code and crashesh without doing anything else
here's the code : `let tweetLabel = AttributedLabel()

    let all = Style.font(.systemFont(ofSize: 20))
    let link = Style
        .foregroundColor(.blue, .normal)


    tweetLabel.attributedText = "@Hey"
        .styleHashtags(link)
        .styleMentions(link)
        .styleLinks(link)
        .styleAll(all)`

adding .foregroundColor(.brown, .highlighted) to link will result. style.swift to crash o.w AttributeText.swift does

issues on xcode9

Hi, I'm using Atributika a while and it's very great, but when I update to xcode 9 there's some error popped up.
Totally 23 issues i'll post some of them below:
Cannot convert value of type '[NSAttributedStringKey : Any]' (aka 'Dictionary<NSString, Any>') to expected argument type '[String : Any]?'

Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'

Type 'NSAttributedStringKey' (aka 'NSString') has no member 'foregroundColor'

Hope you can get it fixed soon.

Thanks

Type issue

Hi !
I have this when i'm trying to build :
Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'

and so on .. :( any help pls ?

Swift 4.2 Support

Great component. Are there any plans for Swift 4.2 support? As of now, it does not compile.

Character highlighting breaks if used \r and \n HTML tags together

Highlighting is missing for few letters of the tagged link. Here is the example text(I am tagging a hashtag with a link)

Worried about delivery? You must know these things!
\r\nLINK
\n <a style="text-decoration:none" href="LINK"><font color="#2b5998">#<font color="#2b5998">Childbirth <a style="text-decoration:none" href="LINK"><font color="#2b5998">#<font color="#2b5998">Expectingababy

If I remove all the \r tags from HTML then it works fine

I cannot add strikethrough attribute.

Here is my sample code. The <code> tag displays well in red color. But the <strike> tag does not show a strikethrough. What seems to be wrong with my code?

let all = Style.font(.systemFont(ofSize: 20))
let strike = Style("strike").strikethroughStyle(.styleSingle).strikethroughColor(.black)
let code = Style("code").foregroundColor(.red)

label5.attributedText = "<code>my code</code> <strike>test</strike> testing"
            .style(tags: [strike,code])
            .styleAll(all)

Honour basic HTML style formatting

Hi,
would it be possible to honour basic HTML styling attributes? We have a basic HTML text like this:
Monday - Friday: <font color="#6cc299"> 8:00 - 19:00</font>
and the tags get transformed / stripped off, but the color attribute is lost. Or is there a way how to achieve this with a TagTransformer anyhow? Please note that the color attribute varies in the HTML text, so applying one style to FONT tag is not the way to go.
Thanks

Link not working

< href="https://www.w3schools.com">This is link I have set this link to 'AttributedLabel' but it not working. when i click on "This is link" it went to case .tag(let tag): and get tag "Tag(name: "a", attributes: [:])". why i am not getting attributes? i have remove <a?> in href for here just to display proper link in issue

Uncheck Gather Coverage Data

When using Carthage [static frameworks], the linker fails. Unchecking Gather Coverage Data in Atributika's test scheme fixes this issue.

AttributedLabel not become sizeToFit()

when i set numberOfLine = 1 it get sizeToFit() but when i try to multiline then AttributedLabel did not set width based on text. Its become full width

A-Tags

Hey! I'm trying to figure out how to convert <a> Tags into clickable links. I tried .style(links:) but that wouldn't work. Do I miss something very obvious?

href support?

I've got the following text:

<p>Je ontvangt je factuur elke maand per post. Daarvoor betaal je € 2,54 per maand. <br />Wil je deze kosten besparen? Meld je dan aan voor een gratis digitale factuur. <a href=\"https://www.google.nl/my/instellingen#betaalgegevens\">Pas je instellingen aan ></a></p>

In the code I've added:

let a = Style("a").foregroundColor(.customRed()).underlineStyle(.styleSingle)
        let all = Style.font(.defaultMediumFont(withSize: 12.0)).foregroundColor(.invoiceRemarksGray()).kern(-0.3)

self.remarksDescriptionLabel.attributedText = decoded.style(tags: a)
                                                        .styleAll(all)
                                                        .stylePhoneNumbers(Style.foregroundColor(.customRed()))
                                                        .styleLinks(Style.foregroundColor(.customRed()))

self.remarksDescriptionLabel.onClick = { label, detection in
            switch detection.type {
...
}

But I never get a onClick event!?

Problems when upload to Apple

Hi,

After archive my project, i got this error when try submit to apple thought Xcode:

2018-07-27 22:10:40 +0000  [OPTIONAL] Didn't find archived user entitlements for <DVTFilePath:0x7fa4ed4b7020:'/Users/paulo/Library/Developer/Xcode/Archives/2018-07-27/xxx 27-07-18 19.10.xcarchive/Products/Applications/XXX.app/Frameworks/Atributika.framework'>:

Error Domain=NSCocoaErrorDomain Code=4 "Item at "/Users/paulo/Library/Developer/Xcode/Archives/2018-07-27/xxx 27-07-18 19.10.xcarchive/Products/Applications/XXX.app/Frameworks/Atributika.framework" did not contain a "archived-expanded-entitlements.xcent" resource."

UserInfo={NSLocalizedDescription=Item at "/Users/paulo/Library/Developer/Xcode/Archives/2018-07-27/xxx 27-07-18 19.10.xcarchive/Products/Applications/XXX.app/Frameworks/Atributika.framework" did not contain a "archived-expanded-entitlements.xcent" resource.}

Styling broken as soon as '&' is found with link display name

Hello Pavel Sharanda,
I'm pleased with this library and intended to use with one of my projects, I would say it's very robust and great in term of performance but there is an issue when a & comes within tag.

Below is the HTML for your reference.

<p><a data-mention=\\\"0F9o0000000PBpMCAW\\\" href=\\\"https://www.google.com\\\”>@Physic & Chemistry</a>\\U00a0<a data-mention=\\\"0F9o000000094o4CAA\\\" href=\\\"https://www.google.com\\\”>@College Success</a>\\U00a0sorry for the short notice, but a great seminar to share with all of you .</p>
I received only Physic as the result nsattributedstring.

A quick reply would be appreciated.

Thanks.

Feature to detect <a href = "">

It works great for all tags of HTML. But using 'a' tag a href = "url" is a major scope. If we could get a support for that, it will be great. Thanks

Images are not loaded

The images in html text do not show at all. How is it possible to implement images while using atributika.

Thanks

BR was not replaced

Hi,

My
tags was not replaced:

image

My code:

 let paragraph = NSMutableParagraphStyle()
paragraph.lineBreakMode = .byTruncatingTail
            
let all = Style.font(.systemFont(ofSize: 14)).foregroundColor(.white).paragraphStyle(paragraph)
lbSynopsis.attributedText = product.synopsis.styleAll(all).attributedString

Can anyone help me?

Support href links?

Is it possible to make href links clickable? I would like to be able to get the 'onClick' event on the AttributedLabel or the link detection on UITextView for this case:
"Hey\r\n<a style=\"text-decoration:none\" href=\"http://www.google.com\">Hello\r\nWorld</a>s"
I currently only managed to get the 'onClick' event for plain links, e.g "Hey http://www.google.com Hello Worlds"

Support case insensitive tags

Hello, before all thank you very much for this library. I would like to ask you if it is possible to add case insensitive tags recognition. For example:

Style("sup")

should match both tags below:

<sup>Superscript</sup>
<SUP>Superscript</SUP>

However only the lowercased tag is matched. At the moment, to overcome this I have to either duplicate the Style for an uppercase condition, or do a string replace.

Detection Button frame issue when using custom font

I have integrated this in tableview cells with automatic layout. Text is displayed properly, however button frame for touch detection appears to be incorrect. PFA the log and the xcode view debugger image. You can check 3 butons frame's. Frame for the 5 points is completely off the track.

button issue

points1.txt

NSTextAttachment does not show image. I'm using attachment() method.

I need help. I cannot display image between text using NSTextAttachment.
Here is my code:

let image1Attachment = NSTextAttachment()
image1Attachment.image = UIImage(named: "profile")

    let all = Style.font(UIFont.systemFont(ofSize: 17)).foregroundColor(.black)
    let atch = Style("attachment").attachment(image1Attachment)
    
    attributed.attributedText = "Hello this is my attachment <attachment></attachment> A simple image"
        .style(tags: [all, atch])
        .styleAll(all)

Text is removed after "&" character when using style

Hi,

I have a text which might include "&" character, for example "Travel & Talk". I would like to format this text and show all the formatted text as an attributed string, but only "Travel" is shown in the result attributed string, rest of the string is removed.

I guess the reason is this line in the String+Detection.swift file:

if let textString = scanner.scanUpToCharacters(from: CharacterSet(charactersIn: "<&")) {
...

Example Code:

let aStyle = Style("a")
            .underlineStyle(.styleSingle)

let html = "Travel & Talk"

let attributedText = html
      .style(tags: aStyle)

print(attributedText)

Result:

AttributedText(string: "Travel ", detections: [], baseStyle: Atributika.Style(name: "", typedAttributes: [:]))

Is there any way that we can also include "&" character in the attributed string?

Support NSTextAttachment in AttributedLabel

Hello!
This library is very excellent.
I am using NSMutableAttributedString to add NSTextAttachment based on the example you gave in https://github.com/psharanda/Atributika/issues/33

It was working well, however when I added onClick on my Attributed label, it cannot detect tag attributes. I think this is because the NSMutableAttributedString doesn't have the detections from the AttributedText.

I have the following code:
It inserts a custom emoji.
I wanted to detect a tag with class mentioned-user
This is a mentioned user but I don't want to use the built-in mentions detection because I want to get the user id from the tag.
plainView.message is the AttributedLabel
Any help is very much appriciated.

//this is the Style I used for my custom mention tag
let span = Style("mentioned").foregroundColor(UIColor.CustomColor.cryptoYellow, .normal)
                .foregroundColor(.blue, .highlighted)

let str = messageTxt.style(tags: tags, transformers: transformers)
let mutableAttrStr = NSMutableAttributedString(attributedString: str.attributedString)

var locationShift = 0
for detection in str.detections {
    switch detection.type {
    case .tag(let tag):
        if let emojiColon =  tag.attributes["colon"] {
            let textAttachment = NSTextAttachment()
            let custom = CustomEmoji.customEmojis[emojiColon]!
            if custom.ext == "gif" {
                if let data = custom.data {
                        let image = UIImage.gif(data: data)
                            textAttachment.image = image
                } else {
                    Alamofire.request(custom.imageUrl).responseImage { (response) in
                        if let image = response.result.value {
                            let image = UIImage.gif(data: response.data!)
                            DispatchQueue.main.async {
                                textAttachment.image = image
                            }
                        }
                    }
                }
            } else {
                textAttachment.image = custom.image
            }
            textAttachment.setImageHeight(20)
            let imageAttrStr = NSAttributedString(attachment: textAttachment)
            let nsrange = NSRange.init(detection.range, in: mutableAttrStr.string)
            mutableAttrStr.insert(imageAttrStr, at: nsrange.location + locationShift)
            locationShift += 1
        }
    default:
        break
    }
}

plainView.message.attributedText = mutableAttrStr
    .styleLinks(link)
    .styleAll(all)
plainView.message.onClick = { label, detection in
    switch detection.type {
    case .tag(let tag):
        let t = tag.attributes
        if let spanClass = t["class"] {
            if spanClass == "mentioned-user" {
                let id = t["data-userid"] ?? ""
                let user_name = t["data-uname"] ?? ""
                self.selectDelegate?.selectedUserId(id)
            }
        } else if let href = t["href"] {
            if let url = URL(string: href) {
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            }
        } else if let type = t["type"] {
            if type == "channel" {
                if let id = t["id"] {
                    self.selectDelegate?.selectedConvo(id)
                }
            }
        }
        default:
        break
    }
}

href support

Hi,
href are not working. The following code snippet is an example. Can you look into it where we did the mistake?
Also, unable to click Facebook link. If I am displaying as Facebook.com, it is clickable.

    let href = "<a href=\"https://www.google.com/\">Google.com</a>  href  <a href=\"https://www.facebook.com/\">Facebook</a>"
    
    let a = Style("a").foregroundColor(.green).underlineStyle(.styleSingle)
    let all = Style.font(.systemFont(ofSize: 20.0)).foregroundColor(.gray)
    let link = Style.foregroundColor(.green, .normal).foregroundColor(.red, .highlighted)
    
    hrefLink.attributedText = href.style(tags: a)
        .styleAll(all)
        .styleLinks(link)
    
    hrefLink.numberOfLines = 0
    
    hrefLink.onClick = { label, detection in
        switch detection.type {
        case .tag(let tag):
            let t = tag.attributes
            if let href = t["href"] {
                if let url = URL(string: href) {
                    if #available(iOS 10.0, *) {
                        UIApplication.shared.open(url, options: [:]
                            , completionHandler: nil)
                    } else {
                        // Fallback on earlier versions
                    }
                }
            }
        case .link(let url):
            UIApplication.shared.open(url, options: [:]
                , completionHandler: nil)
        default:
            break
        }
    }

Give me example

Hi,

I'ld like to use this great module.
Please give me a example working in TableViewCell.
I tried this, but it can't work correctly. it is not tappable.

Thanks.

Swift 4.2

Are there plans for Swift 4.2 support?

screen shot 2018-09-19 at 14 49 57

Italic support

I'm trying to use italic but does Atributika not support < em > and < i > tags?

4.4.0 And missing Symbols

Just pod install'd 4.4.0 and am getting the following:

Undefined symbols for architecture arm64:
  "protocol witness table for __C.NSAttributedStringKey : Swift.Hashable in Foundation", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Dead> of generic specialization <preserving fragile attribute, Atributika.StyleType, [__C.NSAttributedStringKey : Any]> of static (extension in Swift):Swift._NativeDictionaryBuffer< where A: Swift.Hashable>.fromArray([(A, B)]) -> Swift._NativeDictionaryBuffer<A, B> in RegulationDetailController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm not sure this is actually Atributika's problem yet but it's in the error so I thought I"d put it here while I try to track down what is going on. Anyone else see this?

<ul> and <ol> support ?

Hi,

First of all, I am really impressed by this project and appreciate the efforts you put in.
Just want to know, if it possible to support bullet points and numbered list?

I am happy to create a PR if you guide me on how to's and basic project structure.

Installation via CocoaPod

Hello,

I would like to try the library in my project.
Unfortunately CocoaPods shows an error on installation process:

$ pod install
Analyzing dependencies
[!] Unable to find a specification for `Atributika`

My Podfile:

target 'Project'
use_frameworks!
pod 'Atributika'

Is any way to install the Atributika via CocoaPods?

Thanks

Get the frame of a certain range of text so that I can add a custom button or view

Hi!
Thanks for this awesome library! One of the most powerful out there.
I have a question:
Is it possible to get the frame of a specific text using NSRange?
I want to get the frame so that I can add a subview in that coordinate, like a custom button or a view.

For example the text this is a text and this is a button
How can I get the frame of the button word so that I can add a subview in that coordinate that will cover that word.

Any help is greatly appreciated.
Thanks a lot!

Replace HTML Entities

Thanks for such a nice library!
Is there any way to remove / replace html entities like '&laquo'; / '&raquo'; , '&#151'; , and many-many others? Hope there's some easy way to do this and i won't have to replace each entity by myself :)
I was using "html2String" String extension mentioned here early for this

Not adding foreground colours

This is a really nice framework, but I can't seem to get the foreground colour working. I've dropped the first Hello World example directly into my project, but it all shows up black. I'm not sure if I'm missing something.

Xcode 9.3.1 - Undefined symbols - Only when archiving.

Similarly to #27, I'm having compilation errors when archiving with Xcode Version 9.3.1 (9E501).

Undefined symbols for architecture arm64:
  "protocol witness table for __C.NSAttributedStringKey : Swift.Equatable in Foundation", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Dead> of generic specialization <__C.NSAttributedStringKey, Any> of static (extension in Swift):Swift._NativeDictionaryBuffer< where A: Swift.Hashable>.fromArray([(A, B)]) -> Swift._NativeDictionaryBuffer<A, B> in MutableAttributedString+Utils.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Instead of mentioning Hashable, like in #27, my error mentions Equatable.

I was able to fix this by adding:

#if swift(>=4.1)
extension NSAttributedStringKey: Equatable { }
#endif

Would you consider adding this workaround while we wait for the inner Swift bug to be fixed?

Thanks!

Missed attributes

Example of trouble string:
Hello <a class="big" target="" href="http://foo.com">world</a>!
When I click at link framework returns only one attribute entry in tag dictionary
["class":"big"]

Breaks with Swift 4

In Swift 4 NSFontAttributeName is replaced with NSAttributedStringKey.font. I suspect that's the issue.

Full HTML Support?

Is it possible to have full HTML support in this ? I have a label in which I had set attributedText with NSAttributedString which consorting all data with html tags.I need Hash tag detection implementation in that.

Issue with & characters

Text with & characters will strip all styled text following said character. See the following example:

let msg = "Hello & <b>Welcome!</b>"
let b = Style("b").font(Font(name: "Verdana-Bold", size: 22)!)
let strCopy = msg.style(tags: [b]).styleAll(Style.font(Font(name: "Verdana", size: 22)!))
txtView.attributedText = strCopy.attributedString

Displayed text in txtView will simply be: "Hello "

I understand Atributika supports HTML characters so perhaps that is what is causing it? Is it possible to work around that or disable it somehow?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.