How to use the linkify-it function in linkify-it

To help you get started, we’ve selected a few linkify-it 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 ld-x / last-draft / src / plugins / draft-js-linkify-plugin / src / LinkAdd / index.js View on Github external
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import linkifyIt from 'linkify-it';
import modifier from '../modifiers/addLink';
import styles from './styles.css';

const linkify = linkifyIt();

export default class LinkAdd extends Component {
  // Start the popover closed
  state = {
    url: '',
    open: false,
    linkError: false
  };

  // When the popover is open and users click anywhere on the page,
  // the popover should close
  componentDidMount() {
    document.addEventListener('click', this.closePopover);
  }

  componentWillUnmount() {
github appirio-tech / connect-app / src / components / RichTextArea / LinkPlugin / Link / Link.jsx View on Github external
import React, { Component } from 'react'
import linkifyIt from 'linkify-it'
import tlds from 'tlds'

import styles from './Link.scss'

const linkify = linkifyIt()
linkify.tlds(tlds)

// The component we render when we encounter a hyperlink in the text
export default class Link extends Component {
  constructor(props) {
    super(props)

    this.state = {
      editingLink: false
    }
    this.lastDecoratedText = null
  }

  componentDidMount() {
    const { contentState, entityKey, decoratedText } = this.props
    this.lastDecoratedText = decoratedText
github Human-Connection / Human-Connection / webapp / components / Editor / index.vue View on Github external
setLinkUrl(command, url) {
      const links = linkify().match(url)
      if (links) {
        // add valid link
        command({
          href: links.pop().url,
        })
        this.hideLinkMenu()
        this.editor.focus()
      } else if (!url) {
        // remove link
        command({ href: null })
      }
    },
    clear() {
github draft-js-plugins / draft-js-plugins / draft-js-linkify-plugin / src / Link / index.js View on Github external
import React, { Component } from 'react';
import clsx from 'clsx';
import linkifyIt from 'linkify-it';
import tlds from 'tlds';

const linkify = linkifyIt();
linkify.tlds(tlds);

// The component we render when we encounter a hyperlink in the text
export default class Link extends Component {
  render() {
    const {
      decoratedText = '',
      theme = {},
      target = '_self',
      rel = 'noreferrer noopener',
      className,
      component,
      dir, // eslint-disable-line no-unused-vars
      entityKey, // eslint-disable-line no-unused-vars
      getEditorState, // eslint-disable-line no-unused-vars
      offsetKey, // eslint-disable-line no-unused-vars
github mimecuvalo / helloworld / packages / hello-world-editor / plugins / Reply.js View on Github external
import { decoratedBlocksToHTML } from '../utils/Blocks';
import linkifyit from 'linkify-it';
import React from 'react';

const linkify = linkifyit();
linkify.add('> ', {
  validate: function (text, pos, self) {
    const tail = text.slice(pos);
    const schemaLength = tail.indexOf('/');
    const linkLength = linkify.testSchemaAt(tail.slice(schemaLength), 'http:', 0);
    return linkLength ? linkLength + schemaLength : 0;
  },
});

export default (config = {}) => {
  return {
    blockToHTML: decoratedBlocksToHTML(strategy, Component),
    decorators: [
      {
        strategy,
        component: Component,
github meedan / check-web / src / app / components / source / UserInfoEdit.js View on Github external
validateLinks() {
    const linkify = new LinkifyIt();

    let success = true;

    let links = this.state.links ? this.state.links.slice(0) : [];
    links = links.filter(link => !!link.url.trim());

    links.forEach((item_) => {
      const item = item_;
      const url = linkify.match(item.url);
      if (Array.isArray(url) && url[0] && url[0].url) {
        item.url = url[0].url;
      } else {
        item.error = this.props.intl.formatMessage(messages.invalidLink);
        success = false;
      }
    });
github appirio-tech / connect-app / src / components / RichTextArea / AddLinkButton.jsx View on Github external
import React from 'react'
import ReactDOM from 'react-dom'
import {EditorState, RichUtils} from 'draft-js'
import addImage from 'draft-js-image-plugin/lib/modifiers/addImage'
import linkifyIt from 'linkify-it'
import tlds from 'tlds'
import EditorIcons from './EditorIcons'
import Alert from 'react-s-alert'

const linkify = linkifyIt()
linkify.tlds(tlds)

const theme = {
  modalStyles: {
    modalWrapper: 'modalWrapper',
    modalInput: 'modalInput',
    modalButton: 'modalButton',
    modalButtonWrapper: 'modalButtonWrapper',
    modalError: 'modalError'
  }
}

class LinkModal extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
github signalapp / Signal-Desktop / ts / components / conversation / Linkify.tsx View on Github external
import React from 'react';

import LinkifyIt from 'linkify-it';

import { RenderTextCallback } from '../../types/Util';
import { isLinkSneaky } from '../../../js/modules/link_previews';

const linkify = LinkifyIt();

interface Props {
  text: string;
  /** Allows you to customize now non-links are rendered. Simplest is just a <span>. */
  renderNonLink?: RenderTextCallback;
}

const SUPPORTED_PROTOCOLS = /^(http|https):/i;

export class Linkify extends React.Component {
  public static defaultProps: Partial = {
    renderNonLink: ({ text }) =&gt; text,
  };

  public render() {
    const { text, renderNonLink } = this.props;</span>
github berty / berty / js / packages / components / chat / SharedMedias.tsx View on Github external
import { useNavigation } from '@berty-tech/navigation'
import { useTranslation } from 'react-i18next'
import beapi from '@berty-tech/api'
import { useMsgrContext, useConvInteractions, useClient } from '@berty-tech/store/hooks'
import { getSource } from '@berty-tech/components/utils'
import RNFS from 'react-native-fs'
import { timeFormat } from '@berty-tech/components/helpers'
const initialLayout = { width: Dimensions.get('window').width }
import { TabView, SceneMap } from 'react-native-tab-view'
import tlds from 'tlds'
import linkifyFn from 'linkify-it'
import Hyperlink from 'react-native-hyperlink'

import { isBertyDeepLink } from '@berty-tech/components/chat/message/UserMessageComponents'

const linkify = linkifyFn().tlds(tlds, true)

export const SharedMedias: React.FC&lt;{ route: { params: { convPk: string } } }&gt; = ({
	route: {
		params: { convPk },
	},
}) =&gt; {
	const [{ flex, margin, row, text, padding, border, background, color }] = useStyles()
	const { goBack, navigate } = useNavigation()
	const { t }: { t: any } = useTranslation()
	const [activeIndex, setActiveIndex] = useState(0)
	const { protocolClient } = useMsgrContext()
	const [images, setImages] = useState([])
	const client = useClient()

	const messages = useConvInteractions(convPk).filter(
		(msg) =&gt;
github ld-x / last-draft / src / utils / strategy.js View on Github external
/*
 * Copyright (c) 2016, vace.nz (https://github.com/vacenz)
 *
 * License: MIT
 */

import {extractHashtagsWithIndices} from './hashtag'
import linkifyIt from 'linkify-it'
import tlds from 'tlds'

const linkify = linkifyIt()
linkify.tlds(tlds)

export function createTypeStrategy (type) {
  return (contentBlock, callback, contentState) => {
    contentBlock.findEntityRanges(
      (character) => {
        const entityKey = character.getEntity()
        return (
          entityKey !== null &&
          contentState.getEntity(entityKey).getType() === type
        )
      },
      callback
    )
  }
}

linkify-it

Links recognition library with FULL unicode support

MIT
Latest version published 8 months ago

Package Health Score

76 / 100
Full package analysis