ui/lib/shared/addon/helpers/linkify.js

29 lines
606 B
JavaScript

import { helper } from '@ember/component/helper';
import { htmlSafe } from '@ember/string';
import Ember from 'ember';
import linkifyStr from 'linkify-string';
const MAX_LENGTH = 1000;
export function linkify(params) {
let content = params[0] || '';
if ( content.length > MAX_LENGTH ) {
return content;
}
content = Ember.Handlebars.Utils.escapeExpression(content);
content = linkifyStr(content, {
attributes: {
rel: 'nofollow noreferrer',
target: '_blank',
},
defaultProtocol: 'https'
});
return htmlSafe(content);
}
export default helper(linkify);