Skip to content
This repository has been archived by the owner on Apr 4, 2020. It is now read-only.

Commit

Permalink
Make compatible with league/commonmark 1.0.0-beta4
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Jun 5, 2019
1 parent 45070bc commit de2ce9f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased][unreleased]

## [1.0.0-beta2] - 2019-06-05

### Changed

- Made extension compatible with `league/commonmark` 1.0.0-beta4

## [1.0.0-beta1] - 2019-05-27

### Changed
Expand Down Expand Up @@ -47,7 +53,8 @@ This release brings the email and URL autolink processors into alignment with th

Initial release!

[unreleased]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v1.0.0-beta1...HEAD
[unreleased]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v1.0.0-beta2...HEAD
[1.0.0-beta2]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v1.0.0-beta1...v1.0.0-beta2
[1.0.0-beta1]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.3.0...v1.0.0-beta1
[0.3.0]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.2.1...v0.3.0
[0.2.1]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.2.0...v0.2.1
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"require": {
"php" : "^7.1",
"league/commonmark": "^0.19 || ^1.0-beta"
"league/commonmark": "^1.0.0-beta4"
},
"require-dev": {
"phpunit/phpunit": "^7.5"
Expand Down
5 changes: 3 additions & 2 deletions src/AutolinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
namespace League\CommonMark\Ext\Autolink;

use League\CommonMark\ConfigurableEnvironmentInterface;
use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Extension\ExtensionInterface;

final class AutolinkExtension implements ExtensionInterface
{
public function register(ConfigurableEnvironmentInterface $environment)
{
$environment->addDocumentProcessor(new EmailAutolinkProcessor());
$environment->addDocumentProcessor(new UrlAutolinkProcessor());
$environment->addEventListener(DocumentParsedEvent::class, new EmailAutolinkProcessor());
$environment->addEventListener(DocumentParsedEvent::class, new UrlAutolinkProcessor());
}
}
11 changes: 5 additions & 6 deletions src/EmailAutolinkProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@

namespace League\CommonMark\Ext\Autolink;

use League\CommonMark\Block\Element\Document;
use League\CommonMark\DocumentProcessorInterface;
use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Inline\Element\Link;
use League\CommonMark\Inline\Element\Text;

final class EmailAutolinkProcessor implements DocumentProcessorInterface
final class EmailAutolinkProcessor
{
const REGEX = '/([A-Za-z0-9.\-_+]+@[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_.]+)/';

/**
* @param Document $document
* @param DocumentParsedEvent $e
*
* @return void
*/
public function processDocument(Document $document)
public function __invoke(DocumentParsedEvent $e)
{
$walker = $document->walker();
$walker = $e->getDocument()->walker();

while ($event = $walker->next()) {
if ($event->getNode() instanceof Text) {
Expand Down
11 changes: 5 additions & 6 deletions src/UrlAutolinkProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

namespace League\CommonMark\Ext\Autolink;

use League\CommonMark\Block\Element\Document;
use League\CommonMark\DocumentProcessorInterface;
use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Inline\Element\Link;
use League\CommonMark\Inline\Element\Text;

final class UrlAutolinkProcessor implements DocumentProcessorInterface
final class UrlAutolinkProcessor
{
// RegEx adapted from https://github.com/symfony/symfony/blob/4.2/src/Symfony/Component/Validator/Constraints/UrlValidator.php
const REGEX = '~
Expand Down Expand Up @@ -50,13 +49,13 @@ public function __construct(array $allowedProtocols = ['http', 'https', 'ftp'])
}

/**
* @param Document $document
* @param DocumentParsedEvent $e
*
* @return void
*/
public function processDocument(Document $document)
public function __invoke(DocumentParsedEvent $e)
{
$walker = $document->walker();
$walker = $e->getDocument()->walker();

while ($event = $walker->next()) {
if ($event->getNode() instanceof Text) {
Expand Down

0 comments on commit de2ce9f

Please sign in to comment.