PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.6
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 / application / markdown-escaper.php

markdown-escaper.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/llms-txt/application/markdown-escaper.php

45 lines 1.1 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.TooLong
4 namespace Yoast\WP\SEO\Llms_Txt\Application;
5
6 /**
7 * The escaper of markdown.
8 */
9 class Markdown_Escaper {
10
11 /**
12 * Escapes markdown text.
13 *
14 * @param string $text The markdown text to escape.
15 *
16 * @return string The escaped markdown text.
17 */
18 public function escape_markdown_content( $text ) {
19 // We have to decode the text first mostly because ampersands will be escaped below.
20 $text = \html_entity_decode( $text, \ENT_QUOTES, 'UTF-8' );
21
22 // Define a regex pattern for all the special characters in markdown that we want to escape.
23 $pattern = '/[-#*+`._[\]()!&<>_{}|]/';
24
25 $replacement = static function ( $matches ) {
26 return '\\' . $matches[0];
27 };
28
29 return \preg_replace_callback( $pattern, $replacement, $text );
30 }
31
32 /**
33 * Escapes URLs in markdown.
34 *
35 * @param string $url The markdown URL to escape.
36 *
37 * @return string The escaped markdown URL.
38 */
39 public function escape_markdown_url( $url ) {
40 $escaped_url = \str_replace( [ ' ', '(', ')', '\\' ], [ '%20', '%28', '%29', '%5C' ], $url );
41
42 return $escaped_url;
43 }
44 }
45