fix preformatted markup

This commit is contained in:
yggverse 2024-07-14 13:54:55 +03:00
parent 6d37944c04
commit 5b7ff6974e

View file

@ -160,6 +160,17 @@ class Data
case $entity instanceof \Yggverse\Gemtext\Entity\Header: case $entity instanceof \Yggverse\Gemtext\Entity\Header:
if ($preformatted)
{
$line[] = htmlspecialchars(
$this->_wrap(
$entity->toString()
)
);
}
else
{
switch ($entity->getLevel()) switch ($entity->getLevel())
{ {
case 1: // # case 1: // #
@ -210,11 +221,23 @@ class Data
throw new \Exception; throw new \Exception;
} }
}
break; break;
case $entity instanceof \Yggverse\Gemtext\Entity\Link: case $entity instanceof \Yggverse\Gemtext\Entity\Link:
if ($preformatted)
{
$line[] = htmlspecialchars(
$this->_wrap(
$entity->toString()
)
);
}
else
{
$line[] = sprintf( $line[] = sprintf(
'<a href="%s" title="%s">%s</a>', '<a href="%s" title="%s">%s</a>',
$this->_url( $this->_url(
@ -230,11 +253,23 @@ class Data
) )
) )
); );
}
break; break;
case $entity instanceof \Yggverse\Gemtext\Entity\Listing: case $entity instanceof \Yggverse\Gemtext\Entity\Listing:
if ($preformatted)
{
$line[] = htmlspecialchars(
$this->_wrap(
$entity->toString()
)
);
}
else
{
$line[] = sprintf( $line[] = sprintf(
'* %s', '* %s',
htmlspecialchars( htmlspecialchars(
@ -243,11 +278,23 @@ class Data
) )
) )
); );
}
break; break;
case $entity instanceof \Yggverse\Gemtext\Entity\Quote: case $entity instanceof \Yggverse\Gemtext\Entity\Quote:
if ($preformatted)
{
$line[] = htmlspecialchars(
$this->_wrap(
$entity->toString()
)
);
}
else
{
$line[] = sprintf( $line[] = sprintf(
'<i>%s</i>', '<i>%s</i>',
htmlspecialchars( htmlspecialchars(
@ -256,16 +303,29 @@ class Data
) )
) )
); );
}
break; break;
case $entity instanceof \Yggverse\Gemtext\Entity\Text: case $entity instanceof \Yggverse\Gemtext\Entity\Text:
if ($preformatted)
{
$line[] = htmlspecialchars(
$this->_wrap(
$entity->toString()
)
);
}
else
{
$line[] = htmlspecialchars( $line[] = htmlspecialchars(
$this->_wrap( $this->_wrap(
$entity->getData() $entity->getData()
) )
); );
}
break; break;