Skip to content

Commit

Permalink
add links support
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Apr 14, 2024
1 parent cef1551 commit 2cbdcbf
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/Pango.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,39 @@ public static function fromGemtextBody(
}
}

// @TODO links
// Links
foreach ($body->getLinks() as $index => $line)
{
if (!isset($raw[$index]))
{
$link = new \Yggverse\Gemini\Gemtext\Link(
$line
);

if (!$address = $link->getAddress())
{
continue;
}

if (!$alt = $link->getAlt())
{
if (!$alt = $link->getDate())
{
$alt = $address;
}
}

$lines[$index] = sprintf(
'<a href="%s">%s</a>',
$address,
self::escape(
$alt
)
);

$escaped[] = $index;
}
}

// Escape special chars for non escaped lines
foreach ($body->getLines() as $index => $value)
Expand Down

0 comments on commit 2cbdcbf

Please sign in to comment.