Add new options to Autolink #62

Merged
merged 8 commits into from Jun 15, 2012

Conversation

Projects
None yet
2 participants
Contributor

keitaf commented Jun 6, 2012

This will add the following options to Autolink.

  • symbolTag: a tag to apply around symbol (#,@,$) in hashtag/username/list/cashtag links.
  • textWithSymbolTag: a tag to apply around text part in hashtag/username/list/cashtag links.
  • urlTarget: the value of target attribute in URL links
  • linkAttributeBlock: a block/function to modify attributes of a link based on the entity.
  • linkTextBlock: a block/function to modify text of a link based on the entity.

Examples:

  autoLink("#hash", {symbol_tag: "s"}) => "<a...><s>#</s>hash</a>"
  autoLink("#hash", {textWithSymbolTag: "b"}) => "<a...>#<b>hash</b></a>"
  autoLink("#hash", {linkAttributeBlock: function(entity, attributes){
     if (entity.hashtag) { attributes["custom-attr"] = "some_value"; }
  }) => "<a.. custom-attr="some_value"...>#hash</a>"
  autoLink("#hash", {linkTextBlock: function(entity, text){
     return entity.hashtag ? "prefix"+text : text;
  }) => "<a...>prefix#text</a>"

This will also change urlClass option, which is currently applied to all links but will only be applied to URL links.

before, preChunk, postChunk, preText, postText, at and hash options will no longer be available as they are not available in twitter-text-rb/java and they can be replaced by those new options.

Contributor

hoverbird commented Jun 14, 2012

This looks like a good refactoring, and the tests are solid. Are there no new test cases added to the conformance suite, or did I miss those?

Contributor

keitaf commented Jun 14, 2012

I copied & pasted the same test cases instead of adding new tests to the conformance suite because option names are different in different implementations (e.g., "symbolTag" v.s. "symbol_tag") and because we cannot test the options using anonymous functions.

keitaf pushed a commit that referenced this pull request Jun 15, 2012

@keitaf keitaf merged commit 836908a into master Jun 15, 2012

@caniszczyk caniszczyk deleted the autolink_more_options branch Mar 19, 2014

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