diff --git a/Makefile b/Makefile index b3cb81b..60ce194 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,28 @@ -.PHONY: qa lint cs csf phpstan tests coverage +.PHONY: install qa cs csf phpstan tests coverage-clover coverage-html -all: - @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs +install: + composer update -vendor: composer.json composer.lock - composer install +qa: phpstan cs -qa: lint phpstan cs - -lint: vendor - vendor/bin/linter src tests - -cs: vendor +cs: +ifdef GITHUB_ACTION + vendor/bin/codesniffer -q --report=checkstyle src tests | cs2pr +else vendor/bin/codesniffer src tests +endif -csf: vendor +csf: vendor/bin/codefixer src tests -phpstan: vendor +phpstan: vendor/bin/phpstan analyse -l max -c phpstan.neon src -tests: vendor +tests: vendor/bin/tester -s -p php --colors 1 -C tests/cases -coverage: vendor +coverage-clover: vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src tests/cases +coverage-html: + vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.html --coverage-src ./src tests/cases diff --git a/README.md b/README.md index 1203133..1e7c7e9 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,35 @@ -# Latte > Parsedown/Markdown - -:tractor: Markdown parser to Nette Framework. - ------ - -[![Build Status](https://img.shields.io/travis/contributte/latte-parsedown-extra.svg?style=flat-square)](https://travis-ci.org/contributte/latte-parsedown-extra) -[![Code coverage](https://img.shields.io/coveralls/contributte/latte-parsedown-extra.svg?style=flat-square)](https://coveralls.io/r/contributte/latte-parsedown-extra) -[![Licence](https://img.shields.io/packagist/l/contributte/latte-parsedown-extra.svg?style=flat-square)](https://packagist.org/packages/contributte/latte-parsedown-extra) -[![Downloads this Month](https://img.shields.io/packagist/dm/contributte/latte-parsedown-extra.svg?style=flat-square)](https://packagist.org/packages/contributte/latte-parsedown-extra) -[![Downloads total](https://img.shields.io/packagist/dt/contributte/latte-parsedown-extra.svg?style=flat-square)](https://packagist.org/packages/contributte/latte-parsedown-extra) -[![Latest stable](https://img.shields.io/packagist/v/contributte/latte-parsedown-extra.svg?style=flat-square)](https://packagist.org/packages/contributte/latte-parsedown-extra) -[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan) - -## Discussion / Help - -[![Join the chat](https://img.shields.io/gitter/room/contributte/contributte.svg?style=flat-square)](http://bit.ly/ctteg) - -## Install +![](https://heatbadger.now.sh/github/readme/contributte/latte-parsedown-extra/) + +

+ + + + +

+

+ + + + + +

+ +

+ Website 🚀 contributte.org | Contact 👨🏻‍💻 f3l1x.io | Twitter 🐦 @contributte +

+ +## Usage + +To install latest version of `contributte/latte-parsedown-extra` use [Composer](https://getcomposer.com). ``` composer require contributte/latte-parsedown-extra ``` +## Documentation + +For details on how to use this package, check out our [documentation](.docs). + ## Versions | State | Version | Branch | PHP | @@ -31,34 +39,18 @@ composer require contributte/latte-parsedown-extra | stable | `^1.4.0` | `master` | `>= 7.1` | | stable | `^1.2.0` | `master` | `>= 5.6` | -## Overview +## Development -- [Usage - how to install](https://github.com/contributte/latte-parsedown-extra/blob/master/.docs/README.md#usage) -- [Extension - how to configure](https://github.com/contributte/latte-parsedown-extra/blob/master/.docs/README.md#configuration) +See [how to contribute](https://contributte.org) to this package. This package is currently maintained by these authors. -## Maintainers + + + + + + - - - - - - - -
- - - -
- Milan Felix Šulc -
- - - -
- Marek Bartoš -
- ---- +----- -Thank you for testing, reporting and contributing. +Consider to [support](https://contributte.org/partners) **contributte** development team. +Also thank you for using this package. diff --git a/composer.json b/composer.json index 8c5f06b..74848e3 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^7.2", + "php": ">=7.2", "erusev/parsedown": "~1.7.3", "erusev/parsedown-extra": "^0.7.1|^0.8.0", "latte/latte": "~2.5.1|~2.6.0|~2.7.0|~2.8.0", @@ -19,14 +19,13 @@ "nette/utils": "~3.0.0|~3.1.0" }, "require-dev": { - "ninjify/qa": "^0.9", - "ninjify/nunjuck": "^0.2", + "ninjify/qa": "^0.12", + "ninjify/nunjuck": "^0.4", "nette/application": "~3.0.0", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan-deprecation-rules": "^0.11", - "phpstan/phpstan-nette": "^0.11", - "phpstan/phpstan-shim": "^0.11", - "phpstan/phpstan-strict-rules": "^0.11" + "phpstan/phpstan-deprecation-rules": "^0.12", + "phpstan/phpstan-nette": "^0.12", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-strict-rules": "^0.12" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index e69de29..b3f7c06 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -0,0 +1,6 @@ +includes: + - vendor/phpstan/phpstan-nette/extension.neon + - vendor/phpstan/phpstan-nette/rules.neon + - vendor/phpstan/phpstan/conf/bleedingEdge.neon + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/phpstan/phpstan-strict-rules/rules.neon diff --git a/ruleset.xml b/ruleset.xml index 05bd93c..d04d57a 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,20 +1,18 @@ - - - + - + + + + - + /tests/tmp diff --git a/src/DI/ParsedownExtraExtension.php b/src/DI/ParsedownExtraExtension.php index 4129efc..903e29e 100644 --- a/src/DI/ParsedownExtraExtension.php +++ b/src/DI/ParsedownExtraExtension.php @@ -7,7 +7,7 @@ use Nette\Bridges\ApplicationLatte\ILatteFactory; use Nette\DI\CompilerExtension; use Nette\DI\Definitions\FactoryDefinition; -use Nette\DI\Statement; +use Nette\DI\Definitions\Statement; use Nette\InvalidStateException; use Nette\Schema\Expect; use Nette\Schema\Schema; diff --git a/src/ParsedownExtraAdapter.php b/src/ParsedownExtraAdapter.php index 4b55588..5631fea 100644 --- a/src/ParsedownExtraAdapter.php +++ b/src/ParsedownExtraAdapter.php @@ -26,7 +26,7 @@ class ParsedownExtraAdapter */ public function __construct(?ParsedownExtra $parsedown = null) { - $this->parsedown = $parsedown ?: new ParsedownExtra(); + $this->parsedown = $parsedown ?? new ParsedownExtra(); } /** diff --git a/src/ParsedownFilter.php b/src/ParsedownFilter.php index cbebc5b..1c9f4e0 100644 --- a/src/ParsedownFilter.php +++ b/src/ParsedownFilter.php @@ -2,6 +2,8 @@ namespace Contributte\Parsedown; +use Exception; +use Latte\Engine; use Latte\Runtime\FilterInfo; class ParsedownFilter @@ -16,10 +18,15 @@ public function __construct(ParsedownExtraAdapter $adapter) } /** + * @param FilterInfo $info * @param mixed $text */ public function apply(FilterInfo $info, $text): string { + if ($info->contentType !== Engine::CONTENT_HTML) { + throw new Exception('Filter |parsedown used in incompatible content type.'); + } + return $this->adapter->process($text); } diff --git a/tests/cases/ParsedownExtraAdapter.phpt b/tests/cases/ParsedownExtraAdapter.phpt index 2cc8b56..86a175b 100644 --- a/tests/cases/ParsedownExtraAdapter.phpt +++ b/tests/cases/ParsedownExtraAdapter.phpt @@ -12,7 +12,9 @@ test(function (): void { # Headline ## Headline2 + +* 1 '; - Assert::equal("

Headline

\n

Headline2

", $adapter->process($text)); + Assert::equal("

Headline

\n

Headline2

\n", $adapter->process($text)); });