Create link

@param string $text Link text
@param string $href URL
@param string $class Link class
@return string
979738
protected function renderLink($text, $href, $class)
    {
        $a = new NodeElement();
        $a->openTag('a')
          ->addAttributes(array(
            'class' => $class,
            'href' => $href
          ))
          ->finalize(false)
          ->setText($text)
          ->closeTag();

        return $a->render();
    }
506923
public function url($text)
    {
        return preg_replace_callback($this->pattern['url'], function ($matches) {
            return $this->Html->link($matches[2], $matches[1]);
        }, $text);
    }
1263348
static public function linkUrls($text, array $attribs = array()) {
        $htmlAttribs = array();
        foreach ($attribs as $name => $value) {
            $htmlAttribs[] = $name . '="' . $value . '"';
        }
        $htmlAttribs = implode(' ', $htmlAttribs);
        $htmlAttribs = $htmlAttribs ? ' ' . $htmlAttribs : '';

        $regexpProtocol = "/(?:^|\s)((http|https|ftp):\/\/[^\s<]+[\w\/#])([?!,.])?(?=$|\s)/i";
        $regexpWww      = "/(?:^|\s)((www\.)[^\s<]+[\w\/#])([?!,.])?(?=$|\s)/i";

        $text = preg_replace($regexpProtocol, " <a href=\"\\1\"$htmlAttribs>\\1</a>\\3 ", $text);
        $text = preg_replace($regexpWww, " <a href=\"http://\\1\"$htmlAttribs>\\1</a>\\3 ", $text);
        return trim($text);
    }
966071
public static function replaceLinksInTextsWithHrefs(string $text): string
    {
        $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);

        $ret = ' ' . $text;

        // Replace links with http://
        $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $ret);

        // Replace links without http://
        $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $ret);

        // Replace email addresses
        $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
        $ret = substr($ret, 1);

        return $ret;
    }
1372876
static public function linkify($text, array $attribs = array()) {
        return self::linkUrls(self::linkEmailAddresses($text, $attribs), $attribs);
    }
274900
public static function fromText($text, $mode = null)
    {
        $text = nl2br(htmlentities($text, null, 'utf-8'));

        $text = self::createLinks($text);

        return $text;
    }
110516
protected function linkifyMail($text, array &$links, $attr)
    {
        $regexp = '~([^\s<>]+?@[^\s<>]+?\.[^\s<>]+)(?<![\.,:;\?!\'"\|])~';
        
        return preg_replace_callback($regexp, function ($match) use (&$links, $attr) {
            return '<' . array_push($links, '<a' . $attr . ' href="mailto:' . $match[1] . '">' . $match[1] . '</a>')
                . '>';
        }, $text);
    }
470886
function link(href, title, text) {

  var reLabelFirst = /^(.*?)\s*\?([^?\s]*)\?(\*?)(X?)(H?)$/;
  var reLabelAfter = /^\?([^?\s]*)\?(\*?)(X?)(H?)\s*(.*)$/;

  var m = text.match(reLabelFirst);
  if (m) return renderInput(m[1], m[2], m[3], m[4], m[5], href, title, true);

  m = text.match(reLabelAfter);
  if (m) return renderInput(m[5], m[1], m[2], m[3], m[4], href, title, false);

  return fallback.link.call(this, href, title, text);
}
177269
protected function buildSpan( $text, $class = NULL )
	{
		$class 	= $class ? $this->getOption( 'class_span' )." ".$class : $this->getOption( 'class_span' );
		$span	= UI_HTML_Tag::create( "span", $text, array( 'class' => $class ) );
		return $span;
	}
88278
public function createItem($text, $href, $title = '')
    {
        $breadcrumb = new BreadcrumbObject();

        $breadcrumb->setText($text);
        $breadcrumb->setHref($href);

        if ($title) {
            $breadcrumb->setTitle($title);
        }

        $this->breadcrumbs[] = $breadcrumb;

        return $breadcrumb;
    }
34474
public static function create(string $href): LinkBuilderInterface
    {
        $self = new self();
        $self->href = $href;
        $self->rels = [];
        $self->attributes = [];

        return $self;
    }
45516
function linkEntity (cls, url, text) {
  return dom.create('div')
    .class(cls)
    .add(dom.create('a').attr('href', url).add(text))
}
666076
public function makeLinks($text)
    {
        $pattern = '~(?xi)
              (?:
                ((ht|f)tps?://)                    # scheme://
                |                                  #   or
                www\d{0,3}\.                       # "www.", "www1.", "www2." ... "www999."
                |                                  #   or
                www\-                              # "www-"
                |                                  #   or
                [a-z0-9.\-]+\.[a-z]{2,4}(?=/)      # looks like domain name followed by a slash
              )
              (?:                                  # Zero or more:
                [^\s()<>]+                         # Run of non-space, non-()<>
                |                                  #   or
                \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
              )*
              (?:                                  # End with:
                \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
                |                                  #   or
                [^\s`!\-()\[\]{};:\'".,<>?«»“”‘’]  # not a space or one of these punct chars
              )
        ~';

        $callback = function ($urlMatch) {
            $url = $urlMatch[0];

            // Look for protocol
            preg_match('~^(ht|f)tps?://~', $url, $protocolMatch);

            if ($protocolMatch) {
                $protocol = $protocolMatch[0];
            } else {
                $protocol = 'http://';
                $url = $protocol.$url;
            }

            // Start building caption, remove protocol from url
            $noProtocol = substr($url, strlen($protocol));

            // Check for a variation of www
            preg_match('/www\d{0,3}\./', $noProtocol, $wwwMatch);

            if ($wwwMatch) {
                // Remove www
                $noProtocol = substr($noProtocol, strlen($wwwMatch[0]));
            }

            // Only use domain name as caption
            $caption = explode('/', $noProtocol)[0];

            return $this->generateTag('a', $this->linkAttributes + ['href' => $url, $this->externalKey => $caption]);
        };

        return preg_replace_callback($pattern, $callback, $text);
    }
592471
public static function expandUrls(string $text, Tree $tree): string
    {
        // If it looks like a URL, turn it into a markdown autolink.
        $text = preg_replace('/' . addcslashes(self::URL_REGEX, '/') . '/', '<$0>', $text);

        // Create a minimal commonmark processor - just add support for autolinks.
        $environment = new Environment();
        $environment->mergeConfig([
            'renderer'           => [
                'block_separator' => "\n",
                'inner_separator' => "\n",
                'soft_break'      => "\n",
            ],
            'html_input'         => Environment::HTML_INPUT_ESCAPE,
            'allow_unsafe_links' => true,
        ]);

        $environment
            ->addBlockRenderer(Document::class, new DocumentRenderer())
            ->addBlockRenderer(Paragraph::class, new ParagraphRenderer())
            ->addInlineRenderer(Text::class, new TextRenderer())
            ->addInlineRenderer(Link::class, new LinkRenderer())
            ->addInlineParser(new AutolinkParser());

        $environment->addExtension(new CensusTableExtension());
        $environment->addExtension(new XrefExtension($tree));

        $converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));

        try {
            return $converter->convertToHtml($text);
        } catch (Throwable $ex) {
            // See issue #1824
            return $text;
        }
    }
575029
public function twitter($what, $text=null, $class=null) {
		if (is_null($text)) {
			$text = $what;
		}

		$attributes = $this->getHtmlAttributes(array('class'=>$class));

		if (substr($what,0,1)=='@') {
			$link = "https://www.twitter.com/" . ltrim($what, '@');
		} elseif (substr($what,0,1)=='#') {
			$parts = explode(' ', $what);
			if (count($parts)>1) {
				$link = "https://twitter.com/search?q=" . urlencode($what);
			} else {
				$link = "https://www.twitter.com/hashtag/" . ltrim($what, '#');
			}
		}

		return "<a href='$link'$attributes>$text</a>";
	}
258680
public static function autoLinkUrls($text)
    {
        if (strpos($text, '://') === false) {
            // our really quick heuristic failed, abort
            // this may not work so well if we want to match things like
            // "google.com", but then again, most people don't
            return $text;
        }

         $bits = preg_split("/(".self::URL_MATCH.")/ix", $text, -1, PREG_SPLIT_DELIM_CAPTURE);

         $newstring = '';

        // $i = index
        // $c = count
        // $l = is link
        for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
            if (!$l) {
                if ($bits[$i] === '') continue;
                $newstring .= $bits[$i];
            } else {
                $newstring .= '<a href="'.$bits[$i].'">'.$bits[$i].'</a>';
            }
        }
        return $newstring;
    }
976332
protected function buildItem( $text, $class = NULL )
	{
		$list	= array();
		if( $class )
			$list[]	= $class;
		$item	= UI_HTML_Elements::ListItem( $text, 0, array( 'class' => $class ) );
		return $item;
	}