Merge pull request #6 in WFCC/cc34 from 6-Markdown to master

* commit 'a835a4e0f436aa0e64170a295f4e98e4a3a2a5ab':
  Ajout du support du markdown pour la description pour la question 6
This commit is contained in:
Zhu Francois 2023-02-07 19:02:35 +01:00
commit 9b4d948cc6
15 changed files with 539 additions and 430 deletions

View File

@ -51,3 +51,8 @@ symfony console make:crud Atelier
```bash
npm run dev
```
### Question 6
```bash
symfony composer require cebe/markdown "~1.2.0"
```

View File

@ -7,6 +7,7 @@
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"cebe/markdown": "~1.2.0",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.8",
"doctrine/doctrine-migrations-bundle": "^3.2",

66
composer.lock generated
View File

@ -4,8 +4,72 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "bc632d4e0ebaf53085b8673163075690",
"content-hash": "04a6abe7b394e2037e82619227d2a76e",
"packages": [
{
"name": "cebe/markdown",
"version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/cebe/markdown.git",
"reference": "9bac5e971dd391e2802dca5400bbeacbaea9eb86"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/cebe/markdown/zipball/9bac5e971dd391e2802dca5400bbeacbaea9eb86",
"reference": "9bac5e971dd391e2802dca5400bbeacbaea9eb86",
"shasum": ""
},
"require": {
"lib-pcre": "*",
"php": ">=5.4.0"
},
"require-dev": {
"cebe/indent": "*",
"facebook/xhprof": "*@dev",
"phpunit/phpunit": "4.1.*"
},
"bin": [
"bin/markdown"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"autoload": {
"psr-4": {
"cebe\\markdown\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Carsten Brandt",
"email": "mail@cebe.cc",
"homepage": "http://cebe.cc/",
"role": "Creator"
}
],
"description": "A super fast, highly extensible markdown parser for PHP",
"homepage": "https://github.com/cebe/markdown#readme",
"keywords": [
"extensible",
"fast",
"gfm",
"markdown",
"markdown-extra"
],
"support": {
"issues": "https://github.com/cebe/markdown/issues",
"source": "https://github.com/cebe/markdown"
},
"time": "2018-03-26T11:24:36+00:00"
},
{
"name": "doctrine/annotations",
"version": "1.14.3",

View File

@ -22,3 +22,5 @@ services:
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
cebe\markdown\Markdown: ~

View File

@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\Atelier;
use App\Form\AtelierType;
use App\Repository\AtelierRepository;
use App\Services\MarkdownAtelier;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -14,10 +15,11 @@ use Symfony\Component\Routing\Annotation\Route;
class AtelierController extends AbstractController
{
#[Route('/', name: 'app_atelier_index', methods: ['GET'])]
public function index(AtelierRepository $atelierRepository): Response
public function index(AtelierRepository $atelierRepository, MarkdownAtelier $markdown): Response
{
return $this->render('atelier/index.html.twig', [
'ateliers' => $atelierRepository->findAll(),
'ateliers' => $markdown->parseArray($atelierRepository->findAll()),
]);
}
@ -41,10 +43,10 @@ class AtelierController extends AbstractController
}
#[Route('/{id}', name: 'app_atelier_show', methods: ['GET'])]
public function show(Atelier $atelier): Response
public function show(Atelier $atelier, MarkdownAtelier $markdownAtelier): Response
{
return $this->render('atelier/show.html.twig', [
'atelier' => $atelier,
'atelier' => $markdownAtelier->parse($atelier),
]);
}

View File

@ -4,6 +4,7 @@ namespace App\Form;
use App\Entity\Atelier;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -13,7 +14,7 @@ class AtelierType extends AbstractType
{
$builder
->add('nom')
->add('description')
->add('description', TextAreaType::class)
;
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Services;
use App\Entity\Atelier;
use cebe\markdown\Markdown;
class MarkdownAtelier
{
protected $markdown;
public function __construct(Markdown $markdown)
{
$this->markdown = $markdown;
}
public function parse(Atelier $atelier) : Atelier
{
$parseAtelier = $atelier;
$parseAtelier->setDescription($this->markdown->parse($atelier->getDescription()));
return $parseAtelier;
}
public function parseArray(array $ateliers) : array
{
$parsedAteliers = [];
foreach ($ateliers as $atelier) {
$parseAtelier = $atelier;
$parseAtelier->setDescription($this->markdown->parse($atelier->getDescription()));
$parsedAteliers[] = $parseAtelier;
}
return $parsedAteliers;
}
}

View File

@ -19,7 +19,7 @@
<tr>
<td>{{ atelier.id }}</td>
<td>{{ atelier.nom }}</td>
<td>{{ atelier.description }}</td>
<td>{{ atelier.description | raw }}</td>
<td>
<div class="d-flex flex-row">
<a class="btn btn-outline-primary m-1"

View File

@ -17,7 +17,7 @@
</tr>
<tr>
<th>Description</th>
<td>{{ atelier.description }}</td>
<td>{{ atelier.description | raw }}</td>
</tr>
</tbody>
</table>