commit 2691c2dc55d85f73f2b1a7b6dc5e171ab537161a Author: lightbulblighter <59720715+lightbulblighter@users.noreply.github.com> Date: Sat Feb 5 20:17:34 2022 -0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f417e74 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.idea +/vendor diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..247a09c --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: psr2 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..61f2049 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 parsedown, Tadah + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..05a9ee6 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +## ParsedownExtra for Laravel +Imagine [this](https://github.com/parsedown/laravel) but it was [ParsedownExtra](https://github.com/erusev/parsedown-extra). This is what that is. + +Same usage, same documentation, same license, same copyrights. Just swap `Parsedown` for `ParsedownExtra` as the namespace. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..37543b6 --- /dev/null +++ b/composer.json @@ -0,0 +1,50 @@ +{ + "name": "tadah-dev/parsedown-extra", + "description": "Parsedown for Laravel, but with ParsedownExtra", + "keywords": [ + "parsedown", + "laravel", + "parsedownextra" + ], + "license": "MIT", + "support": { + "issues": "https://github.com/tadah-dev/parsedown-extra/issues", + "source": "https://github.com/tadah-dev/parsedown-extra" + }, + "authors": [ + { + "name": "Eduardo Agostini", + "email": "edu.agostini@gmail.com" + }, + { + "name": "Tadah", + "email": "inbox@tadah.rocks" + } + ], + "require": { + "php": ">=7.1.3", + "erusev/parsedown-extra": "^0.8" + }, + "autoload": { + "files": [ + "src/Support/helpers.php" + ], + "psr-4": { + "ParsedownExtra\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "laravel": { + "providers": [ + "ParsedownExtra\\Providers\\ParsedownServiceProvider" + ] + } + } +} diff --git a/src/Providers/ParsedownServiceProvider.php b/src/Providers/ParsedownServiceProvider.php new file mode 100644 index 0000000..f7aa101 --- /dev/null +++ b/src/Providers/ParsedownServiceProvider.php @@ -0,0 +1,70 @@ +compiler()->directive('parsedown', function (string $expression = '') { + return ""; + }); + + $this->publishes([ + __DIR__ . '/../Support/parsedown.php' => config_path('parsedown.php'), + ]); + } + + /** + * @return BladeCompiler + */ + protected function compiler(): BladeCompiler + { + return app('view') + ->getEngineResolver() + ->resolve('blade') + ->getCompiler(); + } + + /** + * @return void + */ + public function register(): void + { + $this->app->singleton('parsedown', function () { + $parsedown = ParsedownExtra::instance(); + + $parsedown->setBreaksEnabled( + Config::get('parsedown.breaks_enabled') + ); + + $parsedown->setMarkupEscaped( + Config::get('parsedown.markup_escaped') + ); + + $parsedown->setSafeMode( + Config::get('parsedown.safe_mode') + ); + + $parsedown->setUrlsLinked( + Config::get('parsedown.urls_linked') + ); + + return $parsedown; + }); + + $this->mergeConfigFrom(__DIR__ . '/../Support/parsedown.php', 'parsedown'); + } +} diff --git a/src/Support/helpers.php b/src/Support/helpers.php new file mode 100644 index 0000000..dd4ee8a --- /dev/null +++ b/src/Support/helpers.php @@ -0,0 +1,28 @@ +line($value); + } + + return $parser->text($value); +} diff --git a/src/Support/parsedown.php b/src/Support/parsedown.php new file mode 100644 index 0000000..5ba7a94 --- /dev/null +++ b/src/Support/parsedown.php @@ -0,0 +1,38 @@ +` tags. + * + * @see https://github.com/erusev/parsedown/wiki/Usage + */ + 'breaks_enabled' => false, + + /** + * Tells the `parsedown()` helper and the `@parsedown` **Blade** directive if the user input should be inline parsed by default. + * + * @see https://github.com/erusev/parsedown/wiki/Usage + */ + 'inline' => false, + + /** + * Tells **Parsedown** if it should escape **HTML** in trusted input. This method isn't safe from XSS! + * + * @see https://github.com/erusev/parsedown#escaping-html + */ + 'markup_escaped' => false, + + /** + * Tells **Parsedown** if it needs to process untrusted user-input. + * + * @see https://github.com/erusev/parsedown#security + */ + 'safe_mode' => true, + + /** + * Tells **Parsedown** if it should automatically convert urls into anchor tags. + * + * @see https://github.com/erusev/parsedown/wiki/Usage + */ + 'urls_linked' => true, +];