Skip to content

Commit

Permalink
return match line number as the array key in result
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Apr 10, 2024
1 parent 55b13c4 commit 526d810
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Gemtext/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public function getH1(): array
{
$matches = [];

foreach ($this->_lines as $line)
foreach ($this->_lines as $index => $line)
{
if (preg_match('/^#([^#]+)/', trim($line), $match))
{
$matches[] = trim(
$matches[$index] = trim(
$match[1]
);
}
Expand All @@ -37,11 +37,11 @@ public function getH2(): array
{
$matches = [];

foreach ($this->_lines as $line)
foreach ($this->_lines as $index => $line)
{
if (preg_match('/^##([^#]+)/', trim($line), $match))
{
$matches[] = trim(
$matches[$index] = trim(
$match[1]
);
}
Expand All @@ -54,11 +54,11 @@ public function getH3(): array
{
$matches = [];

foreach ($this->_lines as $line)
foreach ($this->_lines as $index => $line)
{
if (preg_match('/^###([^#]+)/', trim($line), $match))
{
$matches[] = trim(
$matches[$index] = trim(
$match[1]
);
}
Expand All @@ -71,11 +71,11 @@ public function getLinks(): array
{
$matches = [];

foreach ($this->_lines as $line)
foreach ($this->_lines as $index => $line)
{
if (preg_match('/^=>(.*)/', trim($line), $match))
{
$matches[] = trim(
$matches[$index] = trim(
$match[1]
);
}
Expand All @@ -88,11 +88,11 @@ public function findLinks(string $protocol = 'gemini'): array
{
$matches = [];

foreach ($this->_lines as $line)
foreach ($this->_lines as $index => $line)
{
if (preg_match('/' . $protocol . ':\/\/(.*)[\s\S\'"]*/', trim($line), $match))
{
$matches[] =
$matches[$index] =
sprintf(
'%s://%s',
$protocol,
Expand Down

0 comments on commit 526d810

Please sign in to comment.