diff --git a/.gitignore b/.gitignore index 642f602..285e22b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store vendor composer.lock -composer.phar \ No newline at end of file +composer.phar diff --git a/.travis.yml b/.travis.yml index 102eb02..837c790 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +dist: trusty + language: php php: @@ -5,16 +7,27 @@ php: - 5.5 - 5.6 - 7.0 - - hhvm + - 7.1 + - 7.2 + - 7.3 + - 7.4 + +env: + - COMPOSER_MEMORY_LIMIT=-1 before_script: - composer self-update - composer install --prefer-source --no-interaction --dev + - | + if [ "$TRAVIS_PHP_VERSION" == "5.5" ]; then + echo using PHPUnit 4.8.36 + curl -sSfL -o ~/.phpenv/versions/$TRAVIS_PHP_VERSION/bin/phpunit https://phar.phpunit.de/phpunit-4.8.36.phar; + elif [ $(echo "$TRAVIS_PHP_VERSION >= 7.2" | bc -l) -eq 1 ]; then + echo using PHPUnit 8.5.2 + curl -sSfL -o ~/.phpenv/versions/$TRAVIS_PHP_VERSION/bin/phpunit https://phar.phpunit.de/phpunit-8.5.2.phar; + fi script: phpunit matrix: - allow_failures: - - php: 5.6 - - php: hhvm fast_finish: true diff --git a/README.md b/README.md index 55b31d4..c4981f6 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ #### For Laravel 5+ -1. Run `composer require vtalbot/markdown:2.0` +1. Run `composer require vtalbot/markdown:2.0` 2. Run `php artisan vendor:publish --provider=“VTalbot\Markdown\MarkdownServiceProvider”` 3. Then edit `markdown.php` in your `config` directory to your needs. 4. Add `VTalbot\Markdown\MarkdownServiceProvider::class` to `providers` in `config/app.php` and diff --git a/composer.json b/composer.json index f785133..e9d8b93 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,21 @@ { "name": "vtalbot/markdown", - "description": "Markdown compiler for Laravel 4", + "description": "Markdown compiler for Laravel 5", "keywords": ["laravel", "md", "markdown", "illuminate"], "license": "MIT", - "authors": [ - { - "name": "Vincent Talbot", - "email": "vincent.talbot@gmail.com" - } - ], + "authors": [{ + "name": "Vincent Talbot", + "email": "vincent.talbot@gmail.com" + }], "require": { - "laravel/framework": "~5.0", - "michelf/php-markdown": "1.5.x" + "laravel/framework": "^5||^6||^7||^8", + "michelf/php-markdown": "^1.8" }, "require-dev": { "mockery/mockery": "0.9.0" }, "autoload": { - "psr-0": {"VTalbot\\Markdown": "src/"} + "psr-4": { "VTalbot\\Markdown\\": "src/" } }, "extra": { "branch-alias": { diff --git a/src/config/config.php b/config/config.php similarity index 95% rename from src/config/config.php rename to config/config.php index c88b2b0..4a7931b 100644 --- a/src/config/config.php +++ b/config/config.php @@ -1,6 +1,6 @@ array(), ), -); +]; diff --git a/src/VTalbot/Markdown/Compilers/MarkdownCompiler.php b/src/Compilers/MarkdownCompiler.php similarity index 85% rename from src/VTalbot/Markdown/Compilers/MarkdownCompiler.php rename to src/Compilers/MarkdownCompiler.php index 6d74596..39ba18f 100644 --- a/src/VTalbot/Markdown/Compilers/MarkdownCompiler.php +++ b/src/Compilers/MarkdownCompiler.php @@ -49,6 +49,17 @@ public function string($str) return $contents; } + /** + * Helper to match CommonMark func name + * + * @param string $str + * @return string + */ + public function convertToHtml($str) + { + return $this->string($str); + } + /** * Create a new parser with the options. * diff --git a/src/VTalbot/Markdown/Environment.php b/src/Environment.php similarity index 92% rename from src/VTalbot/Markdown/Environment.php rename to src/Environment.php index d9b3dd2..4b7d4c0 100644 --- a/src/VTalbot/Markdown/Environment.php +++ b/src/Environment.php @@ -139,6 +139,17 @@ public function string($markdown) return $compiler->string($markdown); } + /** + * Helper to match CommonMark func name. + * + * @param string $markdown + * @return string + */ + public function convertToHtml($markdown) + { + return $this->string($markdown); + } + /** * Get the appropriate Markdown engine for the given path. * diff --git a/src/VTalbot/Markdown/Facades/Markdown.php b/src/Facades/Markdown.php similarity index 100% rename from src/VTalbot/Markdown/Facades/Markdown.php rename to src/Facades/Markdown.php diff --git a/src/VTalbot/Markdown/Markdown.php b/src/Markdown.php similarity index 93% rename from src/VTalbot/Markdown/Markdown.php rename to src/Markdown.php index 017a94c..4da82ca 100644 --- a/src/VTalbot/Markdown/Markdown.php +++ b/src/Markdown.php @@ -1,6 +1,6 @@ render(); } -} \ No newline at end of file +} diff --git a/src/VTalbot/Markdown/MarkdownServiceProvider.php b/src/MarkdownServiceProvider.php similarity index 61% rename from src/VTalbot/Markdown/MarkdownServiceProvider.php rename to src/MarkdownServiceProvider.php index fa1d8a0..0e1642d 100644 --- a/src/VTalbot/Markdown/MarkdownServiceProvider.php +++ b/src/MarkdownServiceProvider.php @@ -8,6 +8,7 @@ use Response; use File; use Illuminate\Support\ServiceProvider; +use Illuminate\Contracts\Container\Container; use Illuminate\View\Engines\CompilerEngine; use Illuminate\View\Engines\EngineResolver; use Illuminate\View\FileViewFinder; @@ -16,18 +17,25 @@ class MarkdownServiceProvider extends ServiceProvider { /** - * Register the service provider. + * Bootstrap the application services. * * @return void */ - public function register() + public function boot() { - $this->publishes([ - __DIR__.'/../../config/config.php' => config_path('markdown.php'), - ]); - - $this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'markdown'); + $path_config = __DIR__.'/../config/config.php'; + $publish_path_config = config_path('markdown.php'); + $this->publishes([$path_config => $publish_path_config,], 'config'); + } + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'markdown'); $this->registerRoutes(); $this->registerEngineResolver(); $this->registerMarkdownFinder(); @@ -66,13 +74,13 @@ public function registerEngineResolver() { list($me, $app) = array($this, $this->app); - $app['markdown.engine.resolver'] = $app->share(function($app) use ($me) - { - $resolver = new EngineResolver; - $me->registerMarkdownEngine($resolver); + $this->app->singleton('markdown.engine.resolver', function () use ($app, $me) { + $resolver = new EngineResolver; + $me->registerMarkdownEngine($resolver); + + return $resolver; + }); - return $resolver; - }); } /** @@ -109,17 +117,20 @@ public function registerMarkdownEngine($resolver) */ public function registerMarkdownFinder() { - $this->app['markdown.finder'] = $this->app->share(function($app) - { - $paths = Config::get('markdown.paths'); + $app = $this->app; - foreach ($paths as $key => $path) - { - $paths[$key] = app_path().$path; - } + $this->app->singleton('markdown.finder', function () use ($app) { + + $paths = Config::get('markdown.paths'); + + foreach ($paths as $key => $path) + { + $paths[$key] = app_path().$path; + } + + return new FileViewFinder($app['files'], $paths, array('markdown', 'md')); + }); - return new FileViewFinder($app['files'], $paths, array('markdown', 'md')); - }); } /** @@ -129,24 +140,25 @@ public function registerMarkdownFinder() */ public function registerEnvironment() { - $me = $this; + //$me = $this; + $app = $this->app; - $this->app['markdown'] = $this->app->share(function($app) use ($me) - { - $resolver = $app['markdown.engine.resolver']; + $this->app->singleton('markdown', function () use ($app) { + $resolver = $app['markdown.engine.resolver']; - $finder = $app['markdown.finder']; + $finder = $app['markdown.finder']; - $events = $app['events']; + $events = $app['events']; - $environment = new Environment($resolver, $finder, $events); + $environment = new Environment($resolver, $finder, $events); - $environment->setContainer($app); + $environment->setContainer($app); - $environment->share('app', $app); + $environment->share('app', $app); + + return $environment; + }); - return $environment; - }); } } diff --git a/tests/MarkdownTest.php b/tests/MarkdownTest.php index 9932a60..f6785c7 100644 --- a/tests/MarkdownTest.php +++ b/tests/MarkdownTest.php @@ -3,12 +3,13 @@ use Mockery as m; use VTalbot\Markdown\Compilers\MarkdownCompiler; -class MarkdownTest extends PHPUnit_Framework_TestCase { +class MarkdownTest extends PHPUnit\Framework\TestCase { - public function tearDown() - { - m::close(); - } + // Removed for BC. + // protected function tearDown() + // { + // m::close(); + // } public function testTransformString() {