mirror of
https://github.com/YGGverse/gemini-php.git
synced 2025-09-09 20:52:10 +00:00
add the line methods
This commit is contained in:
parent
526d810406
commit
fc3b82a052
@ -119,10 +119,12 @@ Basic methods to work with `text/gemini` documents
|
|||||||
|
|
||||||
``` php
|
``` php
|
||||||
$body = new \Yggverse\Gemini\Gemtext\Body(
|
$body = new \Yggverse\Gemini\Gemtext\Body(
|
||||||
$response->getBody() // gemtext body from client response or .gmi file
|
$response->getBody() // gemtext body from client response or .gmi file content
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Body::getLines
|
||||||
|
#### Body::getLine
|
||||||
#### Body::getH1
|
#### Body::getH1
|
||||||
#### Body::getH2
|
#### Body::getH2
|
||||||
#### Body::getH3
|
#### Body::getH3
|
||||||
@ -130,7 +132,7 @@ $body = new \Yggverse\Gemini\Gemtext\Body(
|
|||||||
|
|
||||||
``` php
|
``` php
|
||||||
var_dump(
|
var_dump(
|
||||||
$body->getLinks() // returns array of inline links
|
$body->getLinks() // returns array of links (with line number in key)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -140,7 +142,7 @@ Find context links by protocol as argument, `gemini` by default
|
|||||||
|
|
||||||
``` php
|
``` php
|
||||||
var_dump(
|
var_dump(
|
||||||
$body->findLinks('http') // returns array of http links found
|
$body->findLinks('http') // returns array of http links only (with line number in key)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -10,12 +10,22 @@ class Body
|
|||||||
|
|
||||||
public function __construct(string $gemtext)
|
public function __construct(string $gemtext)
|
||||||
{
|
{
|
||||||
foreach ((array) explode(PHP_EOL, $gemtext) as $line)
|
foreach ((array) explode(PHP_EOL, $gemtext) as $index => $line)
|
||||||
{
|
{
|
||||||
$this->_lines[] = $line;
|
$this->_lines[$index] = $line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLine(int $index): ?int
|
||||||
|
{
|
||||||
|
return isset($this->_lines[$index]) ? $this->_lines[$index] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLines(): array
|
||||||
|
{
|
||||||
|
return $this->_lines;
|
||||||
|
}
|
||||||
|
|
||||||
public function getH1(): array
|
public function getH1(): array
|
||||||
{
|
{
|
||||||
$matches = [];
|
$matches = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user