How to use the autolinker function in autolinker

To help you get started, we’ve selected a few autolinker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github euphoria-io / heim / client / lib / ui / message-text.js View on Github external
import _ from 'lodash'
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import Autolinker from 'autolinker'
import twemoji from 'twemoji'
import emoji from '../emoji'

import chat from '../stores/chat'
import hueHash from '../hue-hash'
import heimURL from '../heim-url'


const autolinker = new Autolinker({
  twitter: false,
  truncate: 40,
  replaceFn(self, match) {
    if (match.getType() === 'url') {
      const url = match.getUrl()
      const tag = self.getTagBuilder().build(match)

      if (/^javascript/.test(url.toLowerCase())) {
        // Thanks, Jordan!
        return false
      }

      if (location.protocol === 'https:' && RegExp('^https?:\/\/' + location.hostname).test(url)) {
        // self-link securely
        tag.setAttr('href', url.replace(/^http:/, 'https:'))
      } else {
github RocketChat / Rocket.Chat / packages / rocketchat-autolinker / client / client.js View on Github external
function AutoLinker(message) {
	if (RocketChat.settings.get('AutoLinker') !== true) {
		return message;
	}

	if (s.trim(message.html)) {
		const regUrls = new RegExp(RocketChat.settings.get('AutoLinker_UrlsRegExp'));

		const autolinker = new Autolinker({
			stripPrefix: RocketChat.settings.get('AutoLinker_StripPrefix'),
			urls: {
				schemeMatches: RocketChat.settings.get('AutoLinker_Urls_Scheme'),
				wwwMatches: RocketChat.settings.get('AutoLinker_Urls_www'),
				tldMatches: RocketChat.settings.get('AutoLinker_Urls_TLD'),
			},
			email: RocketChat.settings.get('AutoLinker_Email'),
			phone: RocketChat.settings.get('AutoLinker_Phone'),
			twitter: false,
			stripTrailingSlash: false,
			replaceFn(match) {
				if (match.getType() === 'url') {
					if (regUrls.test(match.matchedText)) {
						if (match.matchedText.indexOf(Meteor.absoluteUrl()) === 0) {
							// returns an `Autolinker.HtmlTag` instance for an <a> tag
							const tag = match.buildTag();</a>
github orbitdb / orbit-web / src / components / textProcessor / react-auto-link.js View on Github external
'use strict'

import React from 'react'
import Autolinker from 'autolinker'

const autolinker = new Autolinker()

// Returns a React element or a string
function reactAutoLink (word, options, wordIndex) {
  const tag = autolinker.parse(word).map(i => i.buildTag())[0]

  if (!tag) return word

  return React.createElement(
    tag.getTagName(),
    Object.assign(tag.attrs, { key: `${tag.attrs.href}-${wordIndex}` }, options),
    tag.getInnerHTML()
  )
}

export default reactAutoLink
github RocketChat / Rocket.Chat / app / autolinker / client / client.js View on Github external
}

		if (!regUrls.test(match.matchedText)) {
			return null;
		}

		if (match.matchedText.indexOf(Meteor.absoluteUrl()) === 0) {
			const tag = match.buildTag();
			tag.setAttr('target', '');
			return tag;
		}

		return true;
	};

	return new Autolinker({
		stripPrefix: settings.get('AutoLinker_StripPrefix'),
		urls: {
			schemeMatches: settings.get('AutoLinker_Urls_Scheme'),
			wwwMatches: settings.get('AutoLinker_Urls_www'),
			tldMatches: settings.get('AutoLinker_Urls_TLD'),
		},
		email: settings.get('AutoLinker_Email'),
		phone: settings.get('AutoLinker_Phone'),
		twitter: false,
		stripTrailingSlash: false,
		replaceFn: replaceAutolinkerMatch,
	});
};
github RocketChat / Rocket.Chat / packages / rocketchat-autolinker / client / client.js View on Github external
}

		if (!regUrls.test(match.matchedText)) {
			return null;
		}

		if (match.matchedText.indexOf(Meteor.absoluteUrl()) === 0) {
			const tag = match.buildTag();
			tag.setAttr('target', '');
			return tag;
		}

		return true;
	};

	return new Autolinker({
		stripPrefix: settings.get('AutoLinker_StripPrefix'),
		urls: {
			schemeMatches: settings.get('AutoLinker_Urls_Scheme'),
			wwwMatches: settings.get('AutoLinker_Urls_www'),
			tldMatches: settings.get('AutoLinker_Urls_TLD'),
		},
		email: settings.get('AutoLinker_Email'),
		phone: settings.get('AutoLinker_Phone'),
		twitter: false,
		stripTrailingSlash: false,
		replaceFn: replaceAutolinkerMatch,
	});
};
github RocketChat / Rocket.Chat / packages / rocketchat-livechat / .app / client / lib / autolinker.js View on Github external
import Autolinker from 'autolinker';

this.livechatAutolinker = new Autolinker({
	twitter: false,
	phone: false,
});
github khlieng / dispatch / client / js / utils / linkify.js View on Github external
import Autolinker from 'autolinker';
import React from 'react';

const autolinker = new Autolinker({
  stripPrefix: false,
  stripTrailingSlash: false
});

export default function linkify(text) {
  if (!text) {
    return text;
  }

  let matches = autolinker.parseText(text);

  if (matches.length === 0) {
    return text;
  }

  const result = [];
github ebates-inc / ebates-chat-kit / src / components / Message / MessageText.js View on Github external
render() {
    const { children, autolink, isOwn } = this.props;

    if (!autolink) {
      return (
        {children}
      );
    }

    let autolinker = new Autolinker( {
        urls : {
          schemeMatches : true,
          wwwMatches    : true,
          tldMatches    : true
        },
        email       : true,
        phone       : true,
        mention     : false,
        hashtag     : false,

        stripPrefix : false,
        stripTrailingSlash : true,
        newWindow   : true,

        truncate : {
            length   : 0,