| @@ -51,16 +51,37 @@ | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | public function parseShortcode($string) |
| 54 | 54 | { |
| 55 | - // check if the string contains any smartcode | |
| 56 | 55 | if (strpos($string, '{{') === false && strpos($string, '##') === false) { |
| 57 | 56 | return $string; |
| 58 | 57 | } |
| 59 | 58 | |
| 59 | + if (static::$isHtml) { | |
| 60 | + $string = $this->resolveHrefPlaceholders($string); | |
| 61 | + } | |
| 62 | + | |
| 60 | 63 | return preg_replace_callback('/({{|##)+(.*?)(}}|##)/', function ($matches) { |
| 61 | 64 | return $this->replace($matches); |
| 62 | 65 | }, $string); |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Resolve placeholders inside href="..." attributes to raw URLs. | |
| 70 | + * Prevents nested anchors when URL smartcodes auto-wrap in HTML mode. | |
| 71 | + */ | |
| 72 | + protected function resolveHrefPlaceholders($string) | |
| 73 | + { | |
| 74 | + return preg_replace_callback( | |
| 75 | + '/(?<![a-zA-Z-])href\s*=\s*(["\'])([^"\']*(?:\{\{|##)[^"\']*)\1/i', | |
| 76 | + function ($m) { | |
| 77 | + static::$isHtml = false; | |
| 78 | + $resolved = $this->parseShortcode($m[2]); | |
| 79 | + static::$isHtml = true; | |
| 80 | + return 'href=' . $m[1] . esc_url($resolved) . $m[1]; | |
| 81 | + }, | |
| 82 | + $string | |
| 83 | + ); | |
| 63 | 84 | } |
| 64 | 85 | |
| 65 | 86 | protected function replace($matches) |
| 66 | 87 | { |