PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.4
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / llms-txt / domain / markdown / items / link.php

link.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.4, at src/llms-txt/domain/markdown/items/link.php

70 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
4 namespace Yoast\WP\SEO\Llms_Txt\Domain\Markdown\Items;
5
6 use Yoast\WP\SEO\Llms_Txt\Application\Markdown_Escaper;
7
8 /**
9 * Represents a link markdown item.
10 */
11 class Link implements Item_Interface {
12
13 /**
14 * The description that is part of this link.
15 *
16 * @var string
17 */
18 private $description;
19
20 /**
21 * The link text.
22 *
23 * @var string
24 */
25 private $text;
26
27 /**
28 * The anchor text.
29 *
30 * @var string
31 */
32 private $anchor;
33
34 /**
35 * Class constructor.
36 *
37 * @param string $text The link text.
38 * @param string $anchor The anchor text.
39 * @param string $description The description.
40 */
41 public function __construct( string $text, string $anchor, string $description = '' ) {
42 $this->text = $text;
43 $this->anchor = $anchor;
44 $this->description = $description;
45 }
46
47 /**
48 * Renders the link item.
49 *
50 * @return string
51 */
52 public function render(): string {
53 $description = ( $this->description !== '' ) ? ": $this->description" : '';
54 return "[$this->text]($this->anchor)$description";
55 }
56
57 /**
58 * Escapes the markdown content.
59 *
60 * @param param Markdown_Escaper $markdown_escaper The markdown escaper.
61 *
62 * @return void
63 */
64 public function escape_markdown( Markdown_Escaper $markdown_escaper ): void {
65 $this->text = $markdown_escaper->escape_markdown_content( $this->text );
66 $this->description = $markdown_escaper->escape_markdown_content( $this->description );
67 $this->anchor = $markdown_escaper->escape_markdown_url( $this->anchor );
68 }
69 }
70