Browse Source

use php line wrap method

PHP-GTK3
yggverse 5 months ago
parent
commit
21575345a0
  1. 54
      src/Entity/Browser/Container/Page/Content/Data.php

54
src/Entity/Browser/Container/Page/Content/Data.php

@ -14,6 +14,9 @@ class Data
// Dependencies // Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Page\Content $content; public \Yggverse\Yoda\Entity\Browser\Container\Page\Content $content;
// Defaults
private int $_wrap = 140;
public function __construct( public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Page\Content $content \Yggverse\Yoda\Entity\Browser\Container\Page\Content $content
) { ) {
@ -31,19 +34,10 @@ class Data
true true
); );
$this->gtk->set_line_wrap(
true
);
$this->gtk->set_can_focus( $this->gtk->set_can_focus(
false false
); );
/* @TODO pending for PR #120
$this->gtk->set_line_wrap_mode(
\PangoWrapMode::WORD
);*/
$this->gtk->set_track_visited_links( $this->gtk->set_track_visited_links(
true true
); );
@ -146,7 +140,9 @@ class Data
$line[] = sprintf( $line[] = sprintf(
'<span size="xx-large">%s</span>', '<span size="xx-large">%s</span>',
htmlspecialchars( htmlspecialchars(
$entity->getText() $this->_wrap(
$entity->getText()
)
) )
); );
@ -163,7 +159,9 @@ class Data
$line[] = sprintf( $line[] = sprintf(
'<span size="x-large">%s</span>', '<span size="x-large">%s</span>',
htmlspecialchars( htmlspecialchars(
$entity->getText() $this->_wrap(
$entity->getText()
)
) )
); );
@ -174,7 +172,9 @@ class Data
$line[] = sprintf( $line[] = sprintf(
'<span size="large">%s</span>', '<span size="large">%s</span>',
htmlspecialchars( htmlspecialchars(
$entity->getText() $this->_wrap(
$entity->getText()
)
) )
); );
@ -197,8 +197,10 @@ class Data
$entity->getAddress() $entity->getAddress()
), ),
htmlspecialchars( htmlspecialchars(
$entity->getAlt() ? $entity->getAlt() $this->_wrap(
: $entity->getAddress() // @TODO date $entity->getAlt() ? $entity->getAlt()
: $entity->getAddress() // @TODO date
)
) )
); );
@ -209,7 +211,9 @@ class Data
$line[] = sprintf( $line[] = sprintf(
'* %s', '* %s',
htmlspecialchars( htmlspecialchars(
$entity->getItem() $this->_wrap(
$entity->getItem()
)
) )
); );
@ -220,7 +224,9 @@ class Data
$line[] = sprintf( $line[] = sprintf(
'<i>%s</i>', '<i>%s</i>',
htmlspecialchars( htmlspecialchars(
$entity->getText() $this->_wrap(
$entity->getText()
)
) )
); );
@ -229,7 +235,9 @@ class Data
case $entity instanceof \Yggverse\Gemtext\Entity\Text: case $entity instanceof \Yggverse\Gemtext\Entity\Text:
$line[] = htmlspecialchars( $line[] = htmlspecialchars(
$entity->getData() $this->_wrap(
$entity->getData()
)
); );
break; break;
@ -248,6 +256,18 @@ class Data
); );
} }
private function _wrap(
string $value
): string
{
return wordwrap(
$value,
$this->_wrap,
PHP_EOL,
false
);
}
private function _url( private function _url(
string $link string $link
): ?string ): ?string

Loading…
Cancel
Save