|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pilipinews\Common\Converters; |
|
4
|
|
|
|
|
5
|
|
|
use League\HTMLToMarkdown\Configuration; |
|
6
|
|
|
use League\HTMLToMarkdown\ConfigurationAwareInterface; |
|
7
|
|
|
use League\HTMLToMarkdown\Converter\ConverterInterface; |
|
8
|
|
|
use League\HTMLToMarkdown\ElementInterface; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Header Converter |
|
12
|
|
|
* |
|
13
|
|
|
* @package Pilipinews |
|
14
|
|
|
* @author Rougin Gutib <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class HeaderConverter implements ConverterInterface, ConfigurationAwareInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var \League\HTMLToMarkdown\Configuration |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $config; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Sets the configuration instance. |
|
25
|
|
|
* |
|
26
|
|
|
* @param \League\HTMLToMarkdown\Configuration $config |
|
27
|
|
|
*/ |
|
28
|
15 |
|
public function setConfig(Configuration $config) |
|
29
|
|
|
{ |
|
30
|
15 |
|
$this->config = $config; |
|
31
|
15 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Converts the specified element into a parsed string. |
|
35
|
|
|
* |
|
36
|
|
|
* @param \League\HTMLToMarkdown\ElementInterface $element |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
3 |
|
public function convert(ElementInterface $element) |
|
40
|
|
|
{ |
|
41
|
3 |
|
$regex = '(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]\.[^\s]{2,})'; |
|
42
|
|
|
|
|
43
|
3 |
|
preg_match($regex, $value = $element->getValue(), $matches); |
|
44
|
|
|
|
|
45
|
3 |
|
if (! isset($matches[0])) |
|
46
|
1 |
|
{ |
|
47
|
3 |
|
$value = mb_convert_case($value, MB_CASE_UPPER, 'UTF-8'); |
|
48
|
1 |
|
} |
|
49
|
|
|
|
|
50
|
3 |
|
return "\n" . $value . "\n"; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns the supported HTML tags. |
|
55
|
|
|
* |
|
56
|
|
|
* @return string[] |
|
57
|
|
|
*/ |
|
58
|
15 |
|
public function getSupportedTags() |
|
59
|
|
|
{ |
|
60
|
15 |
|
return array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|