diff --git a/README.md b/README.md index 54f4190..a03dfcb 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ $body = new \Yggverse\Gemini\Gemtext\Body( #### Body::getH2 #### Body::getH3 #### Body::getQuote +#### Body::getCode #### Body::getLinks ``` php diff --git a/src/Gemtext/Body.php b/src/Gemtext/Body.php index 4c6f721..3cfa3fb 100644 --- a/src/Gemtext/Body.php +++ b/src/Gemtext/Body.php @@ -111,6 +111,21 @@ class Body return $matches; } + public function getCode(): array + { + $matches = []; + + foreach ($this->_lines as $index => $line) + { + if (preg_match('/^```(.*)/', trim($line), $match)) + { + $matches[$index] = empty($match[1]) ? null : trim($match[1]); + } + } + + return $matches; + } + public function findLinks(string $protocol = 'gemini'): array { $matches = [];