From 4e893efd9768cba1c5e5af93989f2f44a87f36b4 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 9 Nov 2019 08:54:08 +0000 Subject: [PATCH] Replace the markdown parser with CommonMark --- app/config/sculpin_kernel.yml | 3 + app/src/Markdown/CommonMarkMarkdownParser.php | 22 ++++++ composer.json | 10 ++- composer.lock | 73 ++++++++++++++++++- 4 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 app/src/Markdown/CommonMarkMarkdownParser.php diff --git a/app/config/sculpin_kernel.yml b/app/config/sculpin_kernel.yml index 8d3b2b3..c2721af 100644 --- a/app/config/sculpin_kernel.yml +++ b/app/config/sculpin_kernel.yml @@ -1,3 +1,6 @@ sculpin_content_types: posts: enabled: false + +parameters: + twig.markdown.parser.class: 'App\Markdown\CommonMarkMarkdownParser' diff --git a/app/src/Markdown/CommonMarkMarkdownParser.php b/app/src/Markdown/CommonMarkMarkdownParser.php new file mode 100644 index 0000000..ffa5a70 --- /dev/null +++ b/app/src/Markdown/CommonMarkMarkdownParser.php @@ -0,0 +1,22 @@ + 'strip', + 'allow_unsafe_links' => false, + ]); + + return $converter->convertToHtml($text); + } +} diff --git a/composer.json b/composer.json index 95e39a0..58b852e 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,9 @@ } ], "require": { - "sculpin/sculpin": "^3.0", - "opdavies/sculpin-twig-markdown-bundle": "dev-markdown" + "league/commonmark": "^1.1", + "opdavies/sculpin-twig-markdown-bundle": "dev-markdown", + "sculpin/sculpin": "^3.0" }, "scripts": { "dev": "composer run-script generate", @@ -26,5 +27,10 @@ "branch-alias": { "dev-master": "2.1-dev" } + }, + "autoload": { + "psr-4": { + "App\\": "app/src" + } } } diff --git a/composer.lock b/composer.lock index 36ad9a2..02ef0fe 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3173aca8bf957af0cd164f430a6bfb4a", + "content-hash": "231dd3f007036b8d3bc7bd9b688a71b6", "packages": [ { "name": "dflydev/ant-path-matcher", @@ -446,6 +446,77 @@ ], "time": "2017-07-23T21:35:13+00:00" }, + { + "name": "league/commonmark", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/commonmark.git", + "reference": "d927c05e9a391688b1e59a606c97465a90531789" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/d927c05e9a391688b1e59a606c97465a90531789", + "reference": "d927c05e9a391688b1e59a606c97465a90531789", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": "^7.1" + }, + "replace": { + "colinodell/commonmark-php": "*" + }, + "require-dev": { + "cebe/markdown": "~1.0", + "commonmark/commonmark.js": "0.29.0", + "erusev/parsedown": "~1.0", + "ext-json": "*", + "michelf/php-markdown": "~1.4", + "mikehaertl/php-shellcommand": "^1.4", + "phpstan/phpstan-shim": "^0.11.5", + "phpunit/phpunit": "^7.5", + "scrutinizer/ocular": "^1.5", + "symfony/finder": "^4.2" + }, + "suggest": { + "league/commonmark-extras": "Library of useful extensions including smart punctuation" + }, + "bin": [ + "bin/commonmark" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "psr-4": { + "League\\CommonMark\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com", + "role": "Lead Developer" + } + ], + "description": "PHP Markdown parser based on the CommonMark spec", + "homepage": "https://commonmark.thephpleague.com", + "keywords": [ + "commonmark", + "markdown", + "parser" + ], + "time": "2019-10-31T13:30:15+00:00" + }, { "name": "michelf/php-markdown", "version": "1.8.0",