codeforamerica / search-rvahealth

Connects Google Spreadsheets to Search
http://search.rvahealth.org
2 stars 3 forks source link

convert any "links" in data to actual URLs #7

Closed mapsam closed 9 years ago

mapsam commented 9 years ago

Convert strings of URLs into actual hyperlinks using some sort of regex magic

mapsam commented 9 years ago

So there's two options here as far as I know:

  1. roll our own regex, which @esmithayer is going to have to do because I'm not a wizard. Something like this?
  2. find a JS library to do this for us.

I'm interested in testing the latter. Here are some potential options:

Mind if I play with these, @esmithayer?

mapsam commented 9 years ago

Pretty neat stuff, these libraries! I'm currently trying out Autolinker.js and it seems to work quite well.

Under init() I started a new instance of the Autolinker library called alink that can be used throughout the scripts. Ran into some issues when passing the newly created string with <a> tags using .innerHTML since that doesn't covert into DOM nodes and just stays as plain text. Work-around uses a Handlebar.registerHelper() function that allows you to pass whatever content through a custom script before it is placed into the Handlebar template. So, new helper exists called add-links:

Handlebars.registerHelper('add-links', function(context) {
  var linked = alink.link(context);
  return new Handlebars.SafeString(linked);
});

and can be used within the template as such:

{{ add-links your_content }}

You'll see it being used only for the "contact" info right now, but couldn't hurt to pass descriptions through this filter as well.

mapsam commented 9 years ago

These Handlebar helpers makes me wonder if we could run {{description}} through a filter looking for "•" entities and creating actual <li> elements... making new issue #13