How to use linkifyjs - 10 common examples

To help you get started, we’ve selected a few linkifyjs 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 DefinitelyTyped / DefinitelyTyped / types / linkifyjs / linkifyjs-tests.tsx View on Github external
tagName: "span"
    });

    linkifyHtml("#swag", {
        tagName: {
            hashtag: "span"
        }
    });

    /* target */

    linkifyHtml("github.com", {
        target: "_parent"
    });

    linkifyHtml("test-email@example.com", {
        target: {
            url: "_parent",
            email: null
        }
    });

    /* validate */

    // Don't linkify links that don't begin in a protocol
    // e.g., "http://google.com" will be linkified, but "google.com" will not.
    linkifyHtml("www.google.com", {
        validate: {
            url(value) {
                return /^(http|ftp)s?:\/\//.test(value);
            }
        }
github DefinitelyTyped / DefinitelyTyped / types / linkifyjs / linkifyjs-tests.tsx View on Github external
linkifyHtml("", {
        events: {
            click(e) {
                alert("Link clicked!");
            },
            mouseover(e) {
                alert("Link hovered!");
            }
        }
    });

    /* defaultProtocol */

    /* format */

    linkifyHtml("", {
        format(value, type) {
            if (type === "url" && value.length > 50) {
                value = value.slice(0, 50) + "…";
            }
            return value;
        }
    });

    linkifyHtml("", {
        format: {
            url(value) {
                return value.length > 50 ? value.slice(0, 50) + "…" : value;
            }
        }
    });
github ntheile / blockusign / Blockusign.Radik / common / lib / notifier / index.js View on Github external
const handleNewModel = async (db, attrs) => {
  // console.log('emitter', attrs);
  if (attrs.radiksType !== 'Message') {
    return true;
  }

  const { content, createdBy } = attrs;
  console.log(`@${createdBy}: ${content}`);
  const matches = linkify.find(content);
  const mentions = {};

  matches.forEach((match) => {
    if (match.type === 'mention') {
      const username = match.value.slice(1);
      mentions[username] = true;
    }
  });

  const mentionedUsers = Object.keys(mentions);

  console.log('Mentions:', mentionedUsers.join(','));

  const centralCollection = db.collection(CENTRAL_COLLECTION);
  const collectMentionsToSend = mentionedUsers.map((username) => new Promise(async (resolve, reject) => {
    try {
github assembl / assembl / assembl / static / js / app / views / messageSend.js View on Github external
_processHyperlinks: _.throttle(function() {
    var that = this,
        messageText = this.ui.messageBody.val()||'',
        links = linkify.find(messageText),
        missingLinks = [],
        goneModels = [];
    //console.log("_processHyperlinks called");
    //console.log(links);
    //console.log(this.attachmentsCollection);

    // this.attachmentsCollection.comparator = function (attachmentModel) {
    //   var index = _.findIndex(links, function(link) {
    //     //console.log(attachmentModel.getDocument().get('uri'), link.href);
    //     return attachmentModel.getDocument().get('uri') === link.href;
    //   })
    //   //console.log("attachmentsCollection comparator returning: ", index);
    //   return index;
    // };
    goneModels = that.attachmentsCollection.filter(function(attachment) {
      var document = attachment.getDocument();
github 01fade / me-and-my-fb-data / src / App.js View on Github external
passToNextState(msgTimes, msgContent){
    let links = [];
    if(msgTimes) {
      console.log("messagestimes", msgTimes.length);
      this.setState({messagesTimes: msgTimes});
    }
    if(msgContent) {
      console.log("messagesContent", msgContent.length);
      links = linkify.find(msgContent).filter((d)=>{return d.type === "url"; });
      this.setState({messagesContent: links});
    }
    // only for DEV
    // this.saveToLocalStorage(msgTimes, links);
    this.setState({dataReady: true});
  }
github Human-Connection / Human-Connection / backend / src / middleware / xssMiddleware.js View on Github external
function clean(dirty) {
  if (!dirty) {
    return dirty
  }

  // Convert embeds to a-tags
  dirty = embedToAnchor(dirty)
  dirty = linkifyHtml(dirty)
  dirty = sanitizeHtml(dirty, {
    allowedTags: [
      'iframe',
      'img',
      'p',
      'h3',
      'h4',
      'br',
      'hr',
      'b',
      'i',
      'em',
      'strong',
      'a',
      'pre',
      'ul',
github Zamiell / hanabi-live / public / js / src / chat.ts View on Github external
export const add = (data: ChatMessage, fast: boolean) => {
    let chat;
    if (data.room === 'lobby') {
        chat = $('#lobby-chat-text');
    } else if ($('#lobby-chat-pregame-text').is(':visible')) {
        chat = $('#lobby-chat-pregame-text');
    } else {
        chat = $('#game-chat-text');
    }
    if (!chat) {
        throw new Error('Failed to get the chat element in the "chat.add()" function.');
    }

    // Linkify any links
    data.msg = linkifyHtml(data.msg, {
        target: '_blank',
    });

    // Convert emotes to images
    data.msg = fillDiscordEmotes(data.msg);
    data.msg = fillLocalEmotes(data.msg);

    // Get the hours and minutes from the time
    const datetime = new Intl.DateTimeFormat(
        undefined,
        {
            hour: '2-digit',
            minute: '2-digit',
            hour12: false,
        },
    ).format(new Date(data.datetime));
github coralproject / talk / services / moderation / phases / links.js View on Github external
module.exports = (
  ctx,
  comment,
  {
    asset: {
      settings: { premodLinksEnable },
    },
  }
) => {
  if (premodLinksEnable) {
    const links = linkify.find(comment.body.replace(/\xAD/g, ''));
    if (!links || links.length === 0) {
      return;
    }

    // Add the flag related to Trust to the comment.
    return {
      status: 'SYSTEM_WITHHELD',
      actions: [
        {
          action_type: 'FLAG',
          user_id: null,
          group_id: 'LINKS',
          metadata: {
            links: comment.body,
          },
        },
github DefinitelyTyped / DefinitelyTyped / types / linkifyjs / linkifyjs-tests.tsx View on Github external
describe("linkifyjs/string", () => {
    /**
     * The following tests were based on the documentation:
     * https://soapbox.github.io/linkifyjs/docs/linkify-string.html
     */
    const options: LinkifyOptions = {};
    const str = '<p>For help with GitHub.com, please email support@github.com</p>';
    const result1: string = linkifyStr(str, options);
    const result2: string = linkifyStr(str);
});
github DefinitelyTyped / DefinitelyTyped / types / linkifyjs / linkifyjs-tests.tsx View on Github external
describe("linkifyjs/string", () =&gt; {
    /**
     * The following tests were based on the documentation:
     * https://soapbox.github.io/linkifyjs/docs/linkify-string.html
     */
    const options: LinkifyOptions = {};
    const str = '<p>For help with GitHub.com, please email support@github.com</p>';
    const result1: string = linkifyStr(str, options);
    const result2: string = linkifyStr(str);
});

linkifyjs

Find URLs, email addresses, #hashtags and @mentions in plain-text strings, then convert them into HTML <a> links.

MIT
Latest version published 5 months ago

Package Health Score

81 / 100
Full package analysis