aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/league/html-to-markdown/src/Converter/ListItemConverter.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-06-05 08:47:24 +0000
committerMario <mario@mariovavti.com>2021-06-05 08:47:24 +0000
commitfd8a5ff4c49fc1361f9928ea4d33e6d24d43a3a5 (patch)
tree7560147f31a273fb8f0e05476f99f1deea0e12de /vendor/league/html-to-markdown/src/Converter/ListItemConverter.php
parent4db384da34595adef68be6226e8b331b4d7b7f31 (diff)
downloadvolse-hubzilla-fd8a5ff4c49fc1361f9928ea4d33e6d24d43a3a5.tar.gz
volse-hubzilla-fd8a5ff4c49fc1361f9928ea4d33e6d24d43a3a5.tar.bz2
volse-hubzilla-fd8a5ff4c49fc1361f9928ea4d33e6d24d43a3a5.zip
composer update league/html-to-markdown
Diffstat (limited to 'vendor/league/html-to-markdown/src/Converter/ListItemConverter.php')
-rw-r--r--vendor/league/html-to-markdown/src/Converter/ListItemConverter.php49
1 files changed, 19 insertions, 30 deletions
diff --git a/vendor/league/html-to-markdown/src/Converter/ListItemConverter.php b/vendor/league/html-to-markdown/src/Converter/ListItemConverter.php
index c56ab89cd..91b3b5dbe 100644
--- a/vendor/league/html-to-markdown/src/Converter/ListItemConverter.php
+++ b/vendor/league/html-to-markdown/src/Converter/ListItemConverter.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
namespace League\HTMLToMarkdown\Converter;
use League\HTMLToMarkdown\Configuration;
@@ -8,39 +10,26 @@ use League\HTMLToMarkdown\ElementInterface;
class ListItemConverter implements ConverterInterface, ConfigurationAwareInterface
{
- /**
- * @var Configuration
- */
+ /** @var Configuration */
protected $config;
- /**
- * @var string
- */
+ /** @var string|null */
protected $listItemStyle;
- /**
- * @param Configuration $config
- */
- public function setConfig(Configuration $config)
+ public function setConfig(Configuration $config): void
{
$this->config = $config;
}
- /**
- * @param ElementInterface $element
- *
- * @return string
- */
- public function convert(ElementInterface $element)
+ public function convert(ElementInterface $element): string
{
// If parent is an ol, use numbers, otherwise, use dashes
- $list_type = $element->getParent()->getTagName();
+ $listType = ($parent = $element->getParent()) ? $parent->getTagName() : 'ul';
// Add spaces to start for nested list items
- $level = $element->getListItemLevel($element);
+ $level = $element->getListItemLevel();
- $prefixForParagraph = str_repeat(' ', $level + 1);
- $value = trim(implode("\n" . $prefixForParagraph, explode("\n", trim($element->getValue()))));
+ $value = \trim(\implode("\n" . ' ', \explode("\n", \trim($element->getValue()))));
// If list item is the first in a nested list, add a newline before it
$prefix = '';
@@ -48,21 +37,21 @@ class ListItemConverter implements ConverterInterface, ConfigurationAwareInterfa
$prefix = "\n";
}
- if ($list_type === 'ul') {
- $list_item_style = $this->config->getOption('list_item_style', '-');
- $list_item_style_alternate = $this->config->getOption('list_item_style_alternate');
- if (!isset($this->listItemStyle)) {
- $this->listItemStyle = $list_item_style_alternate ? $list_item_style_alternate : $list_item_style;
+ if ($listType === 'ul') {
+ $listItemStyle = $this->config->getOption('list_item_style', '-');
+ $listItemStyleAlternate = $this->config->getOption('list_item_style_alternate');
+ if (! isset($this->listItemStyle)) {
+ $this->listItemStyle = $listItemStyleAlternate ?: $listItemStyle;
}
- if ($list_item_style_alternate && $level == 0 && $element->getSiblingPosition() === 1) {
- $this->listItemStyle = $this->listItemStyle == $list_item_style ? $list_item_style_alternate : $list_item_style;
+ if ($listItemStyleAlternate && $level === 0 && $element->getSiblingPosition() === 1) {
+ $this->listItemStyle = $this->listItemStyle === $listItemStyle ? $listItemStyleAlternate : $listItemStyle;
}
return $prefix . $this->listItemStyle . ' ' . $value . "\n";
}
- if ($list_type === 'ol' && $start = $element->getParent()->getAttribute('start')) {
+ if ($listType === 'ol' && ($parent = $element->getParent()) && ($start = \intval($parent->getAttribute('start')))) {
$number = $start + $element->getSiblingPosition() - 1;
} else {
$number = $element->getSiblingPosition();
@@ -74,8 +63,8 @@ class ListItemConverter implements ConverterInterface, ConfigurationAwareInterfa
/**
* @return string[]
*/
- public function getSupportedTags()
+ public function getSupportedTags(): array
{
- return array('li');
+ return ['li'];
}
}