Initial commit

This commit is contained in:
lightbulblighter 2022-02-05 20:17:34 -08:00
commit 2691c2dc55
No known key found for this signature in database
GPG Key ID: 0B2452F9DE0E2D01
8 changed files with 214 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/.idea
/vendor

1
.styleci.yml Normal file
View File

@ -0,0 +1 @@
preset: psr2

21
LICENSE Normal file
View File

@ -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.

4
README.md Normal file
View File

@ -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.

50
composer.json Normal file
View File

@ -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"
]
}
}
}

View File

@ -0,0 +1,70 @@
<?php
namespace ParsedownExtra\Providers;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\Compilers\BladeCompiler;
use ParsedownExtra;
/**
* Class ParsedownServiceProvider
* @package App\Providers
*/
class ParsedownExtraServiceProvider extends ServiceProvider
{
/**
* @return void
*/
public function boot(): void
{
$this->compiler()->directive('parsedown', function (string $expression = '') {
return "<?php echo parsedown($expression); ?>";
});
$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');
}
}

28
src/Support/helpers.php Normal file
View File

@ -0,0 +1,28 @@
<?php
/**
* @param string $value
* @param bool $inline
* @return Parsedown|string
*/
function parsedown(?string $value = null, bool $inline = null)
{
/**
* @var ParsedownExtra $parser
*/
$parser = app('parsedown');
if (!func_num_args()) {
return $parser;
}
if (is_null($inline)) {
$inline = config('parsedown.inline');
}
if ($inline) {
return $parser->line($value);
}
return $parser->text($value);
}

38
src/Support/parsedown.php Normal file
View File

@ -0,0 +1,38 @@
<?php
return [
/**
* Tells **Parsedown** if it should convert line breaks such as `\n` into `<br />` 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,
];