diff options
author | ArthurHoaro <arthur@hoa.ro> | 2021-02-04 10:53:23 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2021-02-04 10:53:23 +0100 |
commit | a1cd7a3b2ff32bf6a0f6083007f59104a85eb4bf (patch) | |
tree | cd1829de149f472d3d891abec120b35bd879a32f /application/formatter | |
parent | 9ef8555ad298668bcb8537ccdd2ab6560f44177f (diff) | |
download | Shaarli-a1cd7a3b2ff32bf6a0f6083007f59104a85eb4bf.tar.gz Shaarli-a1cd7a3b2ff32bf6a0f6083007f59104a85eb4bf.tar.zst Shaarli-a1cd7a3b2ff32bf6a0f6083007f59104a85eb4bf.zip |
ShaarliParsedown: add PHPDoc/comments
Diffstat (limited to 'application/formatter')
3 files changed, 43 insertions, 2 deletions
diff --git a/application/formatter/Parsedown/ShaarliParsedown.php b/application/formatter/Parsedown/ShaarliParsedown.php index d577bdfa..8eb48fda 100644 --- a/application/formatter/Parsedown/ShaarliParsedown.php +++ b/application/formatter/Parsedown/ShaarliParsedown.php | |||
@@ -4,6 +4,11 @@ declare(strict_types=1); | |||
4 | 4 | ||
5 | namespace Shaarli\Formatter\Parsedown; | 5 | namespace Shaarli\Formatter\Parsedown; |
6 | 6 | ||
7 | /** | ||
8 | * Parsedown extension for Shaarli. | ||
9 | * | ||
10 | * Extension for both Parsedown and ParsedownExtra centralized in ShaarliParsedownTrait. | ||
11 | */ | ||
7 | class ShaarliParsedown extends \Parsedown | 12 | class ShaarliParsedown extends \Parsedown |
8 | { | 13 | { |
9 | use ShaarliParsedownTrait; | 14 | use ShaarliParsedownTrait; |
diff --git a/application/formatter/Parsedown/ShaarliParsedownExtra.php b/application/formatter/Parsedown/ShaarliParsedownExtra.php index 92ad26ca..15a35da4 100644 --- a/application/formatter/Parsedown/ShaarliParsedownExtra.php +++ b/application/formatter/Parsedown/ShaarliParsedownExtra.php | |||
@@ -4,6 +4,11 @@ declare(strict_types=1); | |||
4 | 4 | ||
5 | namespace Shaarli\Formatter\Parsedown; | 5 | namespace Shaarli\Formatter\Parsedown; |
6 | 6 | ||
7 | /** | ||
8 | * ParsedownExtra extension for Shaarli. | ||
9 | * | ||
10 | * Extension for both Parsedown and ParsedownExtra centralized in ShaarliParsedownTrait. | ||
11 | */ | ||
7 | class ShaarliParsedownExtra extends \ParsedownExtra | 12 | class ShaarliParsedownExtra extends \ParsedownExtra |
8 | { | 13 | { |
9 | use ShaarliParsedownTrait; | 14 | use ShaarliParsedownTrait; |
diff --git a/application/formatter/Parsedown/ShaarliParsedownTrait.php b/application/formatter/Parsedown/ShaarliParsedownTrait.php index e6f4dabb..ed7b1747 100644 --- a/application/formatter/Parsedown/ShaarliParsedownTrait.php +++ b/application/formatter/Parsedown/ShaarliParsedownTrait.php | |||
@@ -6,24 +6,48 @@ namespace Shaarli\Formatter\Parsedown; | |||
6 | 6 | ||
7 | use Shaarli\Formatter\BookmarkDefaultFormatter as Formatter; | 7 | use Shaarli\Formatter\BookmarkDefaultFormatter as Formatter; |
8 | 8 | ||
9 | /** | ||
10 | * Trait used for Parsedown and ParsedownExtra extension. | ||
11 | * | ||
12 | * Extended: | ||
13 | * - Format links properly in search context | ||
14 | */ | ||
9 | trait ShaarliParsedownTrait | 15 | trait ShaarliParsedownTrait |
10 | { | 16 | { |
17 | /** | ||
18 | * @inheritDoc | ||
19 | */ | ||
11 | protected function inlineLink($excerpt) | 20 | protected function inlineLink($excerpt) |
12 | { | 21 | { |
13 | return $this->shaarliFormatLink(parent::inlineLink($excerpt), true); | 22 | return $this->shaarliFormatLink(parent::inlineLink($excerpt), true); |
14 | } | 23 | } |
15 | 24 | ||
25 | /** | ||
26 | * @inheritDoc | ||
27 | */ | ||
16 | protected function inlineUrl($excerpt) | 28 | protected function inlineUrl($excerpt) |
17 | { | 29 | { |
18 | return $this->shaarliFormatLink(parent::inlineUrl($excerpt), false); | 30 | return $this->shaarliFormatLink(parent::inlineUrl($excerpt), false); |
19 | } | 31 | } |
20 | 32 | ||
33 | /** | ||
34 | * Properly format markdown link: | ||
35 | * - remove highlight tags from HREF attribute | ||
36 | * - (optional) add highlight tags to link caption | ||
37 | * | ||
38 | * @param array|null $link Parsedown formatted link array. | ||
39 | * It can be empty. | ||
40 | * @param bool $fullWrap Add highlight tags the whole link caption | ||
41 | * | ||
42 | * @return array|null | ||
43 | */ | ||
21 | protected function shaarliFormatLink(?array $link, bool $fullWrap): ?array | 44 | protected function shaarliFormatLink(?array $link, bool $fullWrap): ?array |
22 | { | 45 | { |
46 | // If open and clean search tokens are found in the link, process. | ||
23 | if ( | 47 | if ( |
24 | is_array($link) | 48 | is_array($link) |
25 | && strpos($link['element']['attributes']['href'], Formatter::SEARCH_HIGHLIGHT_OPEN) !== false | 49 | && strpos($link['element']['attributes']['href'] ?? '', Formatter::SEARCH_HIGHLIGHT_OPEN) !== false |
26 | && strpos($link['element']['attributes']['href'], Formatter::SEARCH_HIGHLIGHT_CLOSE) !== false | 50 | && strpos($link['element']['attributes']['href'] ?? '', Formatter::SEARCH_HIGHLIGHT_CLOSE) !== false |
27 | ) { | 51 | ) { |
28 | $link['element']['attributes']['href'] = $this->shaarliRemoveSearchTokens( | 52 | $link['element']['attributes']['href'] = $this->shaarliRemoveSearchTokens( |
29 | $link['element']['attributes']['href'] | 53 | $link['element']['attributes']['href'] |
@@ -40,6 +64,13 @@ trait ShaarliParsedownTrait | |||
40 | return $link; | 64 | return $link; |
41 | } | 65 | } |
42 | 66 | ||
67 | /** | ||
68 | * Remove open and close tags from provided string. | ||
69 | * | ||
70 | * @param string $entry input | ||
71 | * | ||
72 | * @return string Striped input | ||
73 | */ | ||
43 | protected function shaarliRemoveSearchTokens(string $entry): string | 74 | protected function shaarliRemoveSearchTokens(string $entry): string |
44 | { | 75 | { |
45 | $entry = str_replace(Formatter::SEARCH_HIGHLIGHT_OPEN, '', $entry); | 76 | $entry = str_replace(Formatter::SEARCH_HIGHLIGHT_OPEN, '', $entry); |