Generates a Markdown link to the given Descriptor or returns the link text if no route to the Descriptor could
be matched.

@param Fqsen|string $link
503873
private function resolveElement(DescriptorAbstract $element, $link, ?string $description = null): string
    {
        $rule = $this->router->match($element);

        if ($rule) {
            $url = '..' . $rule->generate($element);
            $link = $this->generateMarkdownLink($url, $description ?: (string) $link);
        }

        return $link;
    }
545643
private function processLink($text, $link) {
        $link = rtrim($link, '.');
        $pipe = explode('|', $text);

        if (mb_strlen($pipe[0]) !== mb_strlen($text)) {
            $pipe = explode('[', $pipe[0]);
            $linkText = $pipe[1];
            $search = '[' . $linkText . '|' . $link . ']';
            $replace = sprintf('<a href="%s">%s</a>', $link, $linkText);
        } else {
            $search = $link;
            $replace = sprintf('<a href="%s">%s</a>', $link, $link);
        }

        $this->writeRaw(str_replace($search, $replace, $text));

        return '';
    }
867932
private String parseLink(final String link) {
		String[] tokens = link.substring(7, link.length() - 1).split("\\s");
		if (tokens.length == 1) {
			return tokens[0];
		}
		StringBuilder result = new StringBuilder();

		boolean parametersSeen = false;
		boolean inParameters = false;

		for (int index = 0; index < tokens.length; index++) {
			result.append(" ").append(tokens[index]);
			if (tokens[index].indexOf('(') != -1 && !parametersSeen) {
				inParameters = true;
			}
			if (index == 1 && !inParameters) {
				result = new StringBuilder(tokens[index]);
			}
			if (tokens[index].indexOf(')') != -1 && !parametersSeen) {
				parametersSeen = true;
				if (index != tokens.length - 1) {
					result = new StringBuilder();
				}

			}

		}

		return result.toString().trim();
	}
937170
public function setLink($link)
    {
        if (strlen($link) == 0) {
            throw new \InvalidArgumentException(sprintf('TextInput link should not be empty'));
        }

        if (!preg_match('@^https?://@', $link)) {
            throw new \InvalidArgumentException(sprintf('Invalid url: %s', $link));
        }

        $this->link = $link;

        return $this;
    }
164919
public function link($link, $text=null, $title=null, $popup=false, $class=null) {
		if (is_null($text)) {
			// if no text is given, we use the text originally provided by the user
			$text = $link;
		}

		// deal with internal and (slightly) malformed links
		$link = $this->getLink($link);

		$attributes = $this->getHtmlAttributes(array(
			'title'=>$title,
			'target'=>$this->isTrue($popup)?"blank":null,
			'class'=>$class
		));

		return "<a href='$link'$attributes>$text</a>";
	}
1214958
public function setAboutLink($link)
    {
        if (false === filter_var($link, FILTER_VALIDATE_URL)) {
            throw new \InvalidArgumentException(sprintf('Provided link %s is not a valid resource', $link));
        }

        $this->links['about']['href'] = (string) $link;
    }
142463
public function activeLink($link)
    {
        $pathinfo = $this->getPathInfo();
        if (($pathinfo and '/' . $pathinfo === $link) or (!$pathinfo and $link === '/')) {
            return ' active'; //the white space is nedded
        }

        return '';
    }
441839
public function delete($link)
    {
        return $this->getMediaService()->deleteResource($this->getResource(\tao_helpers_Uri::decode($link)));
    }
389496
public function itHasATextSpanLinkedTo($text, $link)
    {
        $this->assertSession()->pageTextContains($text);
        Assertion::assertCount(
            1,
            $this->getXpath()->findXpath(sprintf('//a[@href="%s"]/span[text()="%s"]', $link, $text))
        );
    }
910460
private static function getDocumentedElement($fqsen)
    {
        $projectDescriptor = self::$descriptorBuilder->getProjectDescriptor();
        $elementList = $projectDescriptor->getIndexes()->get('elements');
        $prefixedLink = '~\\' . $fqsen;

        if (isset($elementList[$fqsen])) {
            return $elementList[$fqsen];
        } elseif (isset($elementList[$prefixedLink])) {
            return $elementList[$prefixedLink];
        }

        return false;
    }
406897
public function assertSeeLink($link)
    {
        if ($this->resolver->prefix) {
            $message = "Did not see expected link [{$link}] within [{$this->resolver->prefix}].";
        } else {
            $message = "Did not see expected link [{$link}].";
        }

        PHPUnit::assertTrue(
            $this->seeLink($link),
            $message
        );

        return $this;
    }
354936
public function addLink(Link $link)
    {
        $name = $link->getName();

        if (isset($this->links[$name])) {
            throw new \LogicException(sprintf('A link name by "%s" is already exists.', $name));
        }

        $this->links[$name] = $link;
    }
533519
public static function getRssLink($link = '')
    {
        while (stristr($link, 'http') != $link) {
            $link = substr($link, 1);
        }
        $link = esc_url(strip_tags($link));

        return $link;
    }
255224
public function setLink($link)
    {
        if (strlen($link) == 0) {
            throw new \InvalidArgumentException(sprintf('Image link should not be empty'));
        }

        $this->link = $link;

        return $this;
    }
555309
function readlink($link)
    {
        if (!($this->bitmap & SSH2::MASK_LOGIN)) {
            return false;
        }

        $link = $this->_realpath($link);

        if (!$this->_send_sftp_packet(NET_SFTP_READLINK, pack('Na*', strlen($link), $link))) {
            return false;
        }

        $response = $this->_get_sftp_packet();
        switch ($this->packet_type) {
            case NET_SFTP_NAME:
                break;
            case NET_SFTP_STATUS:
                $this->_logError($response);
                return false;
            default:
                user_error('Expected SSH_FXP_NAME or SSH_FXP_STATUS');
                return false;
        }

        if (strlen($response) < 4) {
            return false;
        }
        extract(unpack('Ncount', $this->_string_shift($response, 4)));
        // the file isn't a symlink
        if (!$count) {
            return false;
        }

        if (strlen($response) < 4) {
            return false;
        }
        extract(unpack('Nlength', $this->_string_shift($response, 4)));
        return $this->_string_shift($response, $length);
    }
773929
protected function getLink($link) {
		$page = new \Phile\Repository\Page();
		$linked_page = $page->findByPath($link);

		if ($linked_page) {
			// the user linked to an internal page
			return \Phile\Utility::getBaseUrl() . '/'. $linked_page->getUrl();
		}

		$file = ROOT_DIR . DIRECTORY_SEPARATOR . $link;
		if (file_exists($file)) {
			// the user linked to an internal file
			return \Phile\Utility::getBaseUrl() . '/' . $link;
		}

		// it's not an internal page, it's not an internal file -
		// let's see if it's (at least) a somewhat valid URL
		$url_parts = parse_url($link);

		if (is_array($url_parts)) {
			if (!array_key_exists("scheme", $url_parts)) {
				// it doesn't have a http:// or https:// or similar prefix.
				// This could mean the user provided something like: (link: cnn.com)
				// -> check if the first part of the link looks like a domain name
				$p = explode('/', $url_parts["path"]);
				$domain = $p[0];

				if ($this->isValidDomainName($domain)) {
					// the first part of the link looks like a valid domain name
					// -> just prepend 'http://' and continue
					return "http://$link";
				}
			}
		}

		// If we get to this point, we just return whatever the user typed.
		return $link;
	}
304316
protected function _makeLink($sLink, $sParams)
    {
        if ($sParams) {
            $sLink .= ((strpos($sLink, '?') !== false) ? '&amp;' : '?') . $sParams;
        }

        return $sLink;
    }