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

Commit

Permalink
Convert this project into a meta-package which includes other officia…
Browse files Browse the repository at this point in the history
…lly-recommended extensions
  • Loading branch information
colinodell committed Mar 15, 2019
1 parent 8858daf commit 1f7ef07
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 325 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- hhvm

env:
matrix:
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ All Notable changes to `commonmark-extras` will be documented in this file

## [Unreleased][unreleased]

**All previous functionality has been removed and placed into separate packages!** This library now serves as a meta-package to pull in officially-recommended extensions.

### Added

- Added [league/commonmark-ext-autolink](https://github.com/thephpleague/commonmark-ext-autolink) and [league/commonmark-ext-smartpunct](https://github.com/thephpleague/commonmark-ext-smartpunct) as dependencies
- Added `CommonMarkExtrasExtension` to pull in both of the libraries above

### Changed

- Moved SmartPunct into its own package: <https://github.com/thephpleague/commonmark-ext-inlines-only>
- Moved the Twitter handle parsing into its own package: <https://github.com/thephpleague/commonmark-ext-autolink>
- Bumped the minimum PHP version up to 5.6
- Bumped the minimum [league/commonmark](https://github.com/thephpleague/commonmark) version to 0.18.1

### Removed

- Removed all classes implementing SmartPunct and Twitter handle parsing as those now live elsewhere
- Removed support for PHP 5.4, PHP 5.5, and HHVM

## [0.1.5] - 2018-09-28
### Changed
- Added league/commonmark 0.18 as a compatible version
Expand Down
11 changes: 4 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ We accept contributions via Pull Requests on [Github](https://github.com/thephpl

## New Extensions & Features

New extensions and features should adhere to the following guidelines:
New extensions and features will only be considered if they meet all of the following criteria:

1. No external dependencies. Only plain PHP code is allowed.
2. Avoid recommended dependencies. If you really need something, mention it in the PR and we'll consider your request.
3. Contributions must have a common use case which other people may find useful.
1. The extension/feature is bundled as a standalone extension, preferably under the PHP League.
2. External dependencies should be avoided where possible - use plain PHP code and common extensions.
3. Contributions must have a common use case found in other flavors of Markdown like GFM which other people may find useful.

## Pull Requests

Expand Down Expand Up @@ -38,9 +38,6 @@ New extensions and features should adhere to the following guidelines:
*
* Authored by Your Name <youremail@domain.com>
*
* Original code based on the CommonMark JS reference parser (http://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
34 changes: 11 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
**league/commonmark-extras** is a collection of useful extensions and utilities
for the [league/commonmark][link-league-commonmark] project.

Adding this extension to your project will automatically register these sub-extensions:

| **Extension** | **Purpose** |
| :------------ | :---------- |
| [league/commonmark-ext-autolink](https://github.com/thephpleague/commonmark-ext-autolink) | Automatically creating links to URLs and email address (without needing the `<...>` syntax) |
| [league/commonmark-ext-smartpunct](https://github.com/thephpleague/commonmark-ext-smartpunct) | Intelligently converts ASCII quotes, dashes, and ellipses to their Unicode equivalents |

## Install

Via Composer
Expand All @@ -20,18 +27,18 @@ $ composer require league/commonmark-extras

## Usage

Extensions can be added to any new `Environment`:
This can be added to any new `Environment`:

``` php
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\Environment;
use League\CommonMark\Extras\SmartPunct\SmartPunctExtension;
use League\CommonMark\Extras\CommonMarkExtrasExtension;

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

// ADD YOUR OWN EXTENSIONS HERE. For example:
$environment->addExtension(new SmartPunctExtension());
// REGISTER THIS EXTENSION HERE
$environment->addExtension(new CommonMarkExtrasExtension());

// Define your configuration:
$config = [];
Expand All @@ -43,19 +50,6 @@ $converter = new CommonMarkConverter($config, $environment);
echo $converter->convertToHtml('# Hello World!');
```

## Extensions

### SmartPunctExtension

Enables Smart punctuation:
Open quotes are matched with closed quotes.

### TwitterHandleAutolink

A Twitter autolink handler. Renders `@handle` as `https://twitter.com/@handle` link

See [Inline Parsing Example](https://commonmark.thephpleague.com/customization/inline-parsing/#example-1---twitter-handles)

## Change log

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
Expand All @@ -66,18 +60,13 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen
$ composer test
```

## Contributing

New features and extensions are welcome! Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

## Security

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

## Credits

- [Colin O'Dell][link-author]
- [John MacFarlane][link-jgm]
- [All Contributors][link-contributors]

## License
Expand All @@ -99,4 +88,3 @@ This library is licensed under the BSD-3 license. See the [License File](LICENS
[link-author]: https://github.com/colinodell
[link-contributors]: ../../contributors
[link-league-commonmark]: https://github.com/thephpleague/commonmark
[link-jgm]: https://github.com/jgm
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "league/commonmark-extras",
"type": "library",
"type": "commonmark-extension",
"description": "Useful extensions for customizing the league/commonmark parser",
"keywords": ["markdown", "commonmark", "extensions", "extras"],
"homepage": "https://github.com/thephpleague/commonmark-extras",
Expand All @@ -14,9 +14,10 @@
}
],
"require": {
"php" : ">=5.4.8",
"league/commonmark": "^0.13|^0.14|^0.15|^0.16|^0.17|^0.18",
"league/commonmark-ext-smartpunct": "^0.1"
"php" : ">=5.6",
"league/commonmark": "^0.18.1",
"league/commonmark-ext-smartpunct": "^0.1",
"league/commonmark-ext-autolink": "^0.1"
},
"require-dev": {
"phpunit/phpunit" : "~4.3|~5.0",
Expand Down
122 changes: 122 additions & 0 deletions src/CommonMarkExtrasExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

/*
* This file is part of the league/commonmark-extras package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace League\CommonMark\Extras;

use League\CommonMark\Ext\Autolink\AutolinkExtension;
use League\CommonMark\Ext\SmartPunct\SmartPunctExtension;
use League\CommonMark\Extension\ExtensionInterface;

final class CommonMarkExtrasExtension implements ExtensionInterface
{
/** @var ExtensionInterface[] */
private $extensions = [];

public function __construct()
{
$this->extensions = [
new SmartPunctExtension(),
new AutolinkExtension(),
];
}

/**
* {@inheritdoc}
*/
public function getBlockParsers()
{
$ret = [];
foreach ($this->extensions as $extension) {
foreach ($extension->getBlockParsers() as $parser) {
$ret[] = $parser;
}
}

This comment has been minimized.

Copy link
@glensc

glensc Mar 18, 2019

Contributor

perhaps add also yield support to commonmark (flatten iterators to array),
so you could do here just:

// php 7.0
// http://php.net/manual/en/language.generators.syntax.php#control-structures.yield.from
yield from $extension->getBlockParsers()

// php 5.6
foreach ($extension->getBlockParsers() as $parser) {
  yield $parser;
}

This comment has been minimized.

Copy link
@colinodell

colinodell Mar 18, 2019

Author Member

The interface for this class will be changing in 0.19 - instead of providing an iteratable list of parsers, we provide a ConfigurableEnvironmentInterface and extensions must call the various ->addBlockParser() etc methods themselves. While we could make this change now for users on 0.18, I don't know whether we'll making a new release of this package prior to the 0.19 release, so it's very possible the change to generators may not be used.


return $ret;
}

/**
* {@inheritdoc}
*/
public function getInlineParsers()
{

$ret = [];
foreach ($this->extensions as $extension) {
foreach ($extension->getInlineParsers() as $parser) {
$ret[] = $parser;
}
}

return $ret;
}

/**
* {@inheritdoc}
*/
public function getInlineProcessors()
{
$ret = [];
foreach ($this->extensions as $extension) {
foreach ($extension->getInlineProcessors() as $processor) {
$ret[] = $processor;
}
}

return $ret;
}

/**
* {@inheritdoc}
*/
public function getDocumentProcessors()
{
$ret = [];
foreach ($this->extensions as $extension) {
foreach ($extension->getDocumentProcessors() as $processor) {
$ret[] = $processor;
}
}

return $ret;
}

/**
* {@inheritdoc}
*/
public function getBlockRenderers()
{
$ret = [];
foreach ($this->extensions as $extension) {
foreach ($extension->getBlockRenderers() as $class => $renderer) {
$ret[$class] = $renderer;
}
}

return $ret;
}

/**
* {@inheritdoc}
*/
public function getInlineRenderers()
{

$ret = [];
foreach ($this->extensions as $extension) {
foreach ($extension->getInlineRenderers() as $class => $renderer) {
$ret[$class] = $renderer;
}
}

return $ret;
}
}
26 changes: 0 additions & 26 deletions src/SmartPunct/PunctuationParser.php

This file was deleted.

26 changes: 0 additions & 26 deletions src/SmartPunct/QuoteParser.php

This file was deleted.

26 changes: 0 additions & 26 deletions src/SmartPunct/QuoteProcessor.php

This file was deleted.

Loading

0 comments on commit 1f7ef07

Please # to comment.