HTML attrs for specific entity types #88

Open
howardr opened this Issue Mar 15, 2013 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

howardr commented Mar 15, 2013

I am finding it difficult to use different html attributes for different entity types (i.e. url, screen name, entity, cashtag). I have ended up recreating the code here...

https://github.com/twitter/twitter-text-rb/blob/v1.6.1/lib/twitter-text/autolink.rb#L67

...to add type specific attrs. In my specific case, I could work around this by using class names, but was curious if you would accept a patch for type specific attributes? Another solution I was thinking would be passing in a block that gets called in #auto_link_entities to allow for specific attributes to be changed (very basic example below)

  Twitter::Rewriter.rewrite_entities(text, entities) do |entity, chars|
    if entity[:url]
      options = options.merge(block.call(:url) || {})
      link_to_url(entity, chars, options, &block)
    elsif entity[:hashtag]
      options = options.merge(block.call(:hashtag) || {})
      link_to_hashtag(entity, chars, options, &block)
    elsif entity[:screen_name]
      options = options.merge(block.call(:screen_name) || {})
      link_to_screen_name(entity, chars, options, &block)
    elsif entity[:cashtag]
      options = options.merge(block.call(:cashtag) || {})
      link_to_cashtag(entity, chars, options, &block)
    end
  end
Contributor

jakl commented Mar 15, 2013

Sure passing a block would be fine, we do that here (maybe using this existing block is even a solution):
https://github.com/twitter/twitter-text-rb/blob/v1.6.1/lib/twitter-text/autolink.rb#L239

What attributes did you need? Can I have some context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment