diff --git a/README.md b/README.md index 2082583..7be841b 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,28 @@ var_dump( #### Link::getAlt +## Pango + +Converter for GTK/Pango format + +### Pango::fromGemtext + +``` php +$pango = \Yggverse\Gemini\Pango::fromGemtext( + $gemtext +); +``` + +### Pango::fromBody + +``` php +$pango = \Yggverse\Gemini\Pango::fromBody( + new \Yggverse\Gemini\Gemtext\Body( + $gemtext + ) +); +``` + ## DokuWiki Toolkit provides DokuWiki API for Gemini. diff --git a/src/Pango.php b/src/Pango.php new file mode 100644 index 0000000..69670e5 --- /dev/null +++ b/src/Pango.php @@ -0,0 +1,86 @@ +getLines(); + + $escaped = []; + + /// Format H1 + foreach ($body->getH1() as $index => $h1) + { + $lines[$index] = sprintf( + '%s', + htmlentities( + $h1 + ) + ); + + $escaped[] = $index; + } + + /// Format H2 + foreach ($body->getH2() as $index => $h2) + { + $lines[$index] = sprintf( + '%s', + htmlentities( + $h2 + ) + ); + + $escaped[] = $index; + } + + /// Format H3 + foreach ($body->getH3() as $index => $h3) + { + $lines[$index] = sprintf( + '%s', + htmlentities( + $h3 + ) + ); + + $escaped[] = $index; + } + + /// Escape entities + foreach ($lines as $index => $line) + { + if (!in_array($index, $escaped)) + { + $lines[$index] = htmlentities( + $line + ); + } + } + + // @TODO links, code, escape entities + + return implode( + PHP_EOL, + $lines + ); + } +} \ No newline at end of file