Markdown   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 13 1
A type() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Rarst\Hugo\wprss2hugo\Serializer;
5
6
use League\HTMLToMarkdown\HtmlConverter;
7
8
/**
9
 * Markdown serializer.
10
 */
11
class Markdown implements Content
12
{
13
    /**
14
     * Convert HTML string to Markdown.
15
     */
16
    public function serialize(string $input): string
17
    {
18
        $converter = new HtmlConverter(['header_style' => 'atx']);
19
20
        // Override HTML comments handling to preserve 'more' tags.
21
        $environment = $converter->getEnvironment();
22
        $environment->addConverter(new CommentConverter());
23
24
        $markdown = $converter->convert($input);
25
        // Ends up with prepended slash for whatever reason...
26
        $markdown = str_replace('\<!--more-->', '<!--more-->', $markdown);
27
28
        return $markdown;
29
    }
30
31
    /**
32
     * Markdown file type.
33
     */
34
    public function type(): string
35
    {
36
        return 'md';
37
    }
38
}
39