Compare commits

...

1 commit

Author SHA1 Message Date
Oliver Davies 4e893efd97 Replace the markdown parser with CommonMark 2019-11-09 08:54:08 +00:00
4 changed files with 105 additions and 3 deletions

View file

@ -1,3 +1,6 @@
sculpin_content_types:
posts:
enabled: false
parameters:
twig.markdown.parser.class: 'App\Markdown\CommonMarkMarkdownParser'

View file

@ -0,0 +1,22 @@
<?php
namespace App\Markdown;
use League\CommonMark\CommonMarkConverter;
use Opdavies\Sculpin\Bundle\TwigMarkdownBundle\Twig\SculpinTwigMarkdownParserInterface;
class CommonMarkMarkdownParser implements SculpinTwigMarkdownParserInterface
{
/**
* {@inheritdoc}
*/
public function transform($text)
{
$converter = new CommonMarkConverter([
'html_input' => 'strip',
'allow_unsafe_links' => false,
]);
return $converter->convertToHtml($text);
}
}

View file

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

73
composer.lock generated
View file

@ -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",