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

Commit de2ce9f

Browse files
committedJun 5, 2019
Make compatible with league/commonmark 1.0.0-beta4
1 parent 45070bc commit de2ce9f

5 files changed

+22
-16
lines changed
 

‎CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased][unreleased]
99

10+
## [1.0.0-beta2] - 2019-06-05
11+
12+
### Changed
13+
14+
- Made extension compatible with `league/commonmark` 1.0.0-beta4
15+
1016
## [1.0.0-beta1] - 2019-05-27
1117

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

4854
Initial release!
4955

50-
[unreleased]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v1.0.0-beta1...HEAD
56+
[unreleased]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v1.0.0-beta2...HEAD
57+
[1.0.0-beta2]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v1.0.0-beta1...v1.0.0-beta2
5158
[1.0.0-beta1]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.3.0...v1.0.0-beta1
5259
[0.3.0]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.2.1...v0.3.0
5360
[0.2.1]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.2.0...v0.2.1

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"require": {
1717
"php" : "^7.1",
18-
"league/commonmark": "^0.19 || ^1.0-beta"
18+
"league/commonmark": "^1.0.0-beta4"
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^7.5"

‎src/AutolinkExtension.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
namespace League\CommonMark\Ext\Autolink;
1313

1414
use League\CommonMark\ConfigurableEnvironmentInterface;
15+
use League\CommonMark\Event\DocumentParsedEvent;
1516
use League\CommonMark\Extension\ExtensionInterface;
1617

1718
final class AutolinkExtension implements ExtensionInterface
1819
{
1920
public function register(ConfigurableEnvironmentInterface $environment)
2021
{
21-
$environment->addDocumentProcessor(new EmailAutolinkProcessor());
22-
$environment->addDocumentProcessor(new UrlAutolinkProcessor());
22+
$environment->addEventListener(DocumentParsedEvent::class, new EmailAutolinkProcessor());
23+
$environment->addEventListener(DocumentParsedEvent::class, new UrlAutolinkProcessor());
2324
}
2425
}

‎src/EmailAutolinkProcessor.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@
1111

1212
namespace League\CommonMark\Ext\Autolink;
1313

14-
use League\CommonMark\Block\Element\Document;
15-
use League\CommonMark\DocumentProcessorInterface;
14+
use League\CommonMark\Event\DocumentParsedEvent;
1615
use League\CommonMark\Inline\Element\Link;
1716
use League\CommonMark\Inline\Element\Text;
1817

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

2322
/**
24-
* @param Document $document
23+
* @param DocumentParsedEvent $e
2524
*
2625
* @return void
2726
*/
28-
public function processDocument(Document $document)
27+
public function __invoke(DocumentParsedEvent $e)
2928
{
30-
$walker = $document->walker();
29+
$walker = $e->getDocument()->walker();
3130

3231
while ($event = $walker->next()) {
3332
if ($event->getNode() instanceof Text) {

‎src/UrlAutolinkProcessor.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111

1212
namespace League\CommonMark\Ext\Autolink;
1313

14-
use League\CommonMark\Block\Element\Document;
15-
use League\CommonMark\DocumentProcessorInterface;
14+
use League\CommonMark\Event\DocumentParsedEvent;
1615
use League\CommonMark\Inline\Element\Link;
1716
use League\CommonMark\Inline\Element\Text;
1817

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

5251
/**
53-
* @param Document $document
52+
* @param DocumentParsedEvent $e
5453
*
5554
* @return void
5655
*/
57-
public function processDocument(Document $document)
56+
public function __invoke(DocumentParsedEvent $e)
5857
{
59-
$walker = $document->walker();
58+
$walker = $e->getDocument()->walker();
6059

6160
while ($event = $walker->next()) {
6261
if ($event->getNode() instanceof Text) {

0 commit comments

Comments
 (0)