HTML attrs for specific entity types #88

howardr opened this Issue Mar 15, 2013 · 1 comment


None yet
2 participants

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... 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( || {})
      link_to_url(entity, chars, options, &block)
    elsif entity[:hashtag]
      options = options.merge( || {})
      link_to_hashtag(entity, chars, options, &block)
    elsif entity[:screen_name]
      options = options.merge( || {})
      link_to_screen_name(entity, chars, options, &block)
    elsif entity[:cashtag]
      options = options.merge( || {})
      link_to_cashtag(entity, chars, options, &block)

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):

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