eldargab / easy-table

Nice text table for Node.js
314 stars 31 forks source link

Set column width for Hyperlinks with Slack adapter #17

Closed amitnavindgi closed 6 years ago

amitnavindgi commented 6 years ago

Hi @eldargab ,

Let's say I have a text 'Click here' in a table cell. Now, if I want to link this to, say google.com, the actual text in the table cell be prefixed with hyperlink formatting as per slack's specification mentioned here.

So the code for table cell be something like,

t.cell('label', '<http://www.google.com|Click here>');

The hyperlink part works fine when sent to slack but the width of that column considers the actual text including the URL, <http://www.google.com|Click here>, as expected and hence is very long when the actual cell content is only 'Click here'. Is there a way I can set the column width to avoid this? Not sure if printer can be used here.

Thanks!

eldargab commented 6 years ago

Hello,

yes, printer is definitely enough to handle this. For example

function link(s, len) {
  if (len != null) return s
  var last = s.split('|')[1]
  return last.slice(0, last.length - 1)
}

t.cell('label', '<http://www.google.com|Click here>', link)