mirror of
https://github.com/YGGverse/gemtext-php.git
synced 2026-03-31 09:45:33 +00:00
update Parser API, implement Document:getEntities(), Document:append() methods
This commit is contained in:
parent
f00f23aaf2
commit
d5cd8c184d
1 changed files with 38 additions and 14 deletions
52
src/Document.php
Normal file → Executable file
52
src/Document.php
Normal file → Executable file
|
|
@ -15,71 +15,83 @@ class Document
|
|||
) {
|
||||
foreach ((array) explode(PHP_EOL, $data) as $line)
|
||||
{
|
||||
// Init match
|
||||
$matches = [];
|
||||
|
||||
// Add entity
|
||||
switch (true)
|
||||
{
|
||||
// Code
|
||||
case Parser\Code::match($line):
|
||||
case Parser\Code::match($line, $matches):
|
||||
|
||||
$this->_entity[] = new Entity\Code(
|
||||
Parser\Code::getAlt(
|
||||
$line
|
||||
$line,
|
||||
$matches
|
||||
),
|
||||
Parser\Code::isInline(
|
||||
$line
|
||||
$line,
|
||||
$matches
|
||||
)
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
// Header
|
||||
case Parser\Header::match($line):
|
||||
case Parser\Header::match($line, $matches):
|
||||
|
||||
$this->_entity[] = new Entity\Header(
|
||||
Parser\Header::getText(
|
||||
$line
|
||||
$line,
|
||||
$matches
|
||||
),
|
||||
Parser\Header::getLevel(
|
||||
$line
|
||||
$line,
|
||||
$matches
|
||||
)
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
// Link
|
||||
case Parser\Link::match($line):
|
||||
case Parser\Link::match($line, $matches):
|
||||
|
||||
$this->_entity[] = new Entity\Link(
|
||||
Parser\Link::getAddress(
|
||||
$line
|
||||
$line,
|
||||
$matches
|
||||
),
|
||||
Parser\Link::getAlt(
|
||||
$line
|
||||
$line,
|
||||
$matches
|
||||
),
|
||||
Parser\Link::getDate(
|
||||
$line
|
||||
$line,
|
||||
$matches
|
||||
)
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
// Listing
|
||||
case Parser\Listing::match($line):
|
||||
case Parser\Listing::match($line, $matches):
|
||||
|
||||
$this->_entity[] = new Entity\Listing(
|
||||
Parser\Listing::getItem(
|
||||
$line
|
||||
$line,
|
||||
$matches
|
||||
)
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
// Quote
|
||||
case Parser\Quote::match($line):
|
||||
case Parser\Quote::match($line, $matches):
|
||||
|
||||
$this->_entity[] = new Entity\Quote(
|
||||
Parser\Quote::getText(
|
||||
$line
|
||||
$line,
|
||||
$matches
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -95,6 +107,11 @@ class Document
|
|||
}
|
||||
}
|
||||
|
||||
public function getEntities(): array
|
||||
{
|
||||
return $this->_entity;
|
||||
}
|
||||
|
||||
public function getHeaders(): array
|
||||
{
|
||||
$headers = [];
|
||||
|
|
@ -155,6 +172,13 @@ class Document
|
|||
return $quotes;
|
||||
}
|
||||
|
||||
public function append(
|
||||
\Yggverse\Gemtext\Interface\Entity $entity
|
||||
): void
|
||||
{
|
||||
$this->_entity[] = $entity;
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
$lines = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue