Browse Source

add null values support

main
ghost 9 months ago
parent
commit
3cfef3ee67
  1. 20
      src/Dokuwiki/Reader.php

20
src/Dokuwiki/Reader.php

@ -161,10 +161,17 @@ class Reader @@ -161,10 +161,17 @@ class Reader
}
// Convert DokuWiki text to Gemini
public function toGemini(string $data, ?array &$lines = []): string
public function toGemini(?string $data, ?array &$lines = []): ?string
{
if (empty($gemini))
{
return null;
}
$raw = false;
$lines = [];
foreach ((array) explode(PHP_EOL, $data) as $line)
{
// Skip any formatting in lines between code tag
@ -247,9 +254,9 @@ class Reader @@ -247,9 +254,9 @@ class Reader
);
}
public function getH1(string $gemini, ?string $regex = '/^[\s]?#([^#]+)/'): ?string
public function getH1(?string $gemini, ?string $regex = '/^[\s]?#([^#]+)/'): ?string
{
foreach ((array) explode(PHP_EOL, $gemini) as $line)
foreach ((array) explode(PHP_EOL, (string) $gemini) as $line)
{
preg_match(
$regex,
@ -270,10 +277,15 @@ class Reader @@ -270,10 +277,15 @@ class Reader
return null;
}
public function getLinks(string $gemini, ?string $regex = '/(https?|gemini):\/\/\S+/'): array
public function getLinks(?string $gemini, ?string $regex = '/(https?|gemini):\/\/\S+/'): array
{
$links = [];
if (empty($gemini))
{
return $links;
}
preg_match_all(
$regex,
$gemini,

Loading…
Cancel
Save