1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* part-db version 0.1 |
5
|
|
|
* Copyright (C) 2005 Christoph Lechner |
6
|
|
|
* http://www.cl-projects.de/ |
7
|
|
|
* |
8
|
|
|
* part-db version 0.2+ |
9
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
10
|
|
|
* http://code.google.com/p/part-db/ |
11
|
|
|
* |
12
|
|
|
* Part-DB Version 0.4+ |
13
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
14
|
|
|
* https://github.com/jbtronics |
15
|
|
|
* |
16
|
|
|
* This program is free software; you can redistribute it and/or |
17
|
|
|
* modify it under the terms of the GNU General Public License |
18
|
|
|
* as published by the Free Software Foundation; either version 2 |
19
|
|
|
* of the License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU General Public License |
27
|
|
|
* along with this program; if not, write to the Free Software |
28
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
namespace App\Services; |
33
|
|
|
|
34
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* This class allows you to convert markdown text to HTML. |
38
|
|
|
* @package App\Services |
39
|
|
|
*/ |
40
|
|
|
class MarkdownParser |
41
|
|
|
{ |
42
|
|
|
protected $translator; |
43
|
|
|
|
44
|
|
|
public function __construct(TranslatorInterface $translator) |
45
|
|
|
{ |
46
|
|
|
$this->translator = $translator; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Mark the markdown for rendering. |
51
|
|
|
* The rendering of markdown is done on client side |
52
|
|
|
* @param string $markdown The markdown text that should be parsed to html. |
53
|
|
|
* @param bool $inline_mode Only allow inline markdown codes like (*bold* or **italic**), not something like tables |
54
|
|
|
* @return string The markdown in a version that can be parsed on client side. |
55
|
|
|
*/ |
56
|
|
|
public function markForRendering(string $markdown, bool $inline_mode = false) : string |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
return sprintf( |
59
|
|
|
'<div class="markdown" data-markdown="%s">%s</div>', |
60
|
|
|
htmlspecialchars($markdown), |
61
|
|
|
$this->translator->trans('markdown.loading') |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.