Skip to content

Commit

Permalink
add the line methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Apr 10, 2024
1 parent 526d810 commit fc3b82a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,20 @@ Basic methods to work with `text/gemini` documents

``` php
$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::getH2
#### Body::getH3
#### Body::getLinks

``` php
var_dump(
$body->getLinks() // returns array of inline links
$body->getLinks() // returns array of links (with line number in key)
);
```

Expand All @@ -140,7 +142,7 @@ Find context links by protocol as argument, `gemini` by default

``` php
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)
);
```

Expand Down
14 changes: 12 additions & 2 deletions src/Gemtext/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ class Body

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
{
$matches = [];
Expand Down

0 comments on commit fc3b82a

Please sign in to comment.