PHPackages                             league/commonmark-ext-external-link - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. league/commonmark-ext-external-link

Abandoned → [league/commonmark](/?search=league%2Fcommonmark)ArchivedCommonmark-extension[Parsing &amp; Serialization](/categories/parsing)

league/commonmark-ext-external-link
===================================

Extension for league/commonmark which adds extra classes and HTML attributes to external links

v1.1.0(6y ago)68.5k3BSD-3-ClausePHPPHP ^7.1

Since May 19Pushed 6y ago5 watchersCompare

[ Source](https://github.com/thephpleague/commonmark-ext-external-link)[ Packagist](https://packagist.org/packages/league/commonmark-ext-external-link)[ Docs](https://github.com/thephpleague/commonmark-ext-external-link)[ GitHub Sponsors](https://github.com/colinodell)[ Patreon](https://www.patreon.com/colinodell)[ RSS](/packages/league-commonmark-ext-external-link/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

Extension to denote external links for `league/commonmark`
==========================================================

[](#extension-to-denote-external-links-for-leaguecommonmark)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2d6e1f16c0cc07c7848d5e07b294a3db4d04ddac05143cd6f929ef91fd13bed4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c65616775652f636f6d6d6f6e6d61726b2d6578742d65787465726e616c2d6c696e6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/commonmark-ext-external-link)[![Software License](https://camo.githubusercontent.com/f4927c28d46f9aff0a32ba934d27da23943c7e31876f86d6362e41a56e9c66ad/687474703a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4253442d2d332d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/4dce9f66f9e21ef044ccb4656c95135034259f658bea299b3d8a4b637b180a95/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7468657068706c65616775652f636f6d6d6f6e6d61726b2d6578742d65787465726e616c2d6c696e6b2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/thephpleague/commonmark-ext-external-link)[![Coverage Status](https://camo.githubusercontent.com/733b0d0a1702962ca4008dfc759f4584fb37bfeac2351d1fa9fe1a266f2a8ce1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7468657068706c65616775652f636f6d6d6f6e6d61726b2d6578742d65787465726e616c2d6c696e6b2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/commonmark-ext-external-link/code-structure)[![Quality Score](https://camo.githubusercontent.com/ddb0080e24894fe7ab645d18a96d327beecc989b770322c55259ed57c1e6a5eb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7468657068706c65616775652f636f6d6d6f6e6d61726b2d6578742d65787465726e616c2d6c696e6b2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/commonmark-ext-external-link)[![Total Downloads](https://camo.githubusercontent.com/f336b0aefc51df779c8493abbd80a5e1089384e49b98017ab1efbb1f77176ee0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f636f6d6d6f6e6d61726b2d6578742d65787465726e616c2d6c696e6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/commonmark-ext-external-link)

DEPRECATED
----------

[](#deprecated)

**This extension has been deprecated**. All of its functionality now exists in [`league/commonmark`](https://github.com/thephpleague/commonmark) 1.3+ under the `League\CommonMark\Extension\ExternalLink` namespace, so you should upgrade to that version and use that bundled extension instead of this one.

Overview
--------

[](#overview)

This extension to the [`league/commonmark` PHP Markdown parser](https://github.com/thephpleague/commonmark) can detect links to external sites and adjust the markup accordingly:

- Adds a `rel="noopener noreferrer"` attribute
- Optionally adds any custom HTML classes

Install
-------

[](#install)

Via Composer

```
$ composer require league/commonmark-ext-external-link
```

Usage
-----

[](#usage)

Configure your `Environment` as usual and simply add the `ExternalLinkExtension` provided by this package:

```
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\Environment;
use League\CommonMark\Ext\ExternalLink\ExternalLinkExtension;

// Obtain a pre-configured Environment with all the CommonMark parsers/renderers ready-to-go
$environment = Environment::createCommonMarkEnvironment();

// Add this extension
$environment->addExtension(new ExternalLinkExtension());

// Set your configuration
$config = [
    'external_link' => [
        'internal_hosts' => 'www.example.com',
        'open_in_new_window' => true,
        'html_class' => 'external-link',
    ],
];

// Instantiate the converter engine and start converting some Markdown!
$converter = new CommonMarkConverter($config, $environment);
echo $converter->convertToHtml('I successfully installed the https://github.com/thephpleague/commonmark-ext-external-link extension!');
```

Configuration
-------------

[](#configuration)

This extension supports three configuration options under the `external_link` configuration:

### `internal_hosts`

[](#internal_hosts)

This option defines a whitelist of hosts which are considered non-external and should not receive the external link treatment.

This can be a single host name, like `'example.com'`, which must match exactly.

If you need to match subdomains, use a regular expression like `'/(^|\.)example\.com$/'`. Note that you must use `/` characters to delimit your regex.

This configuration option also accepts an array of multiple strings and/or regexes:

```
$config = [
    'external_link' => [
        'internal_hosts' => ['foo.example.com', 'bar.example.com', '/(^|\.)google\.com$/],
    ],
];
```

By default, if this option is not provided, all links will be considered external.

### `open_in_new_window`

[](#open_in_new_window)

This option (which defaults to `false`) determines whether any external links should open in a new tab/window.

### `html_class`

[](#html_class)

This option allows you to provide a `string` containing one or more HTML classes that should be added to the external link `` tags: No classes are added by default.

Advanced Rendering
------------------

[](#advanced-rendering)

When an external link is detected, the `ExternalLinkProcessor` will set the `external` data option on the `Link` node to either `true` or `false`. You can therefore create a [custom link renderer](https://commonmark.thephpleague.com/customization/inline-rendering/) which checks this value and behaves accordingly:

```
class MyCustomLinkRenderer implements InlineRendererInterface
{

    /**
     * @param Link                     $inline
     * @param ElementRendererInterface $htmlRenderer
     *
     * @return HtmlElement
     */
    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
    {
        if (!($inline instanceof Link)) {
            throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
        }

        if ($inline->getData('external')) {
            // This is an external link - render it accordingly
        } else {
            // This is an internal link
        }

        // ...
    }
}
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Colin O'Dell](https://github.com/colinodell)
- [All Contributors](../../contributors)

License
-------

[](#license)

This library is licensed under the BSD-3 license. See the [License File](LICENSE) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~107 days

Total

4

Last Release

2236d ago

Major Versions

v0.1.0 → v1.0.0-beta12019-06-05

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/534693?v=4)[Frank de Jonge](/maintainers/frankdejonge)[@frankdejonge](https://github.com/frankdejonge)

![](https://www.gravatar.com/avatar/4325b62a6ad366c731c3120595d861469be50f9da88df3ea99752c30ff98c179?d=identicon)[colinodell](/maintainers/colinodell)

---

Top Contributors

[![colinodell](https://avatars.githubusercontent.com/u/202034?v=4)](https://github.com/colinodell "colinodell (13 commits)")

---

Tags

commonmarkcommonmark-extensionexternal-linksmarkdownphpmarkdowncommonmarkextensionlinks

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/league-commonmark-ext-external-link/health.svg)

```
[![Health](https://phpackages.com/badges/league-commonmark-ext-external-link/health.svg)](https://phpackages.com/packages/league-commonmark-ext-external-link)
```

###  Alternatives

[zoon/commonmark-ext-youtube-iframe

Extension for league/commonmark to replace youtube link with iframe

12275.9k1](/packages/zoon-commonmark-ext-youtube-iframe)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
