aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php
diff options
context:
space:
mode:
authornobody <nobody@zotlabs.com>2021-06-17 14:57:47 -0700
committernobody <nobody@zotlabs.com>2021-06-17 14:57:47 -0700
commitefda8aac1d7d90fd7eda4a449332eedf74342951 (patch)
tree3373c0579168776cccda5224b6b33ce59fa9b274 /vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php
parent686530c1873f98d724355bf3f456243b1b7fdadd (diff)
parenta84cec4acddf6804a88fcda52e4437c91785dfb2 (diff)
downloadvolse-hubzilla-efda8aac1d7d90fd7eda4a449332eedf74342951.tar.gz
volse-hubzilla-efda8aac1d7d90fd7eda4a449332eedf74342951.tar.bz2
volse-hubzilla-efda8aac1d7d90fd7eda4a449332eedf74342951.zip
Merge branch 'dev' of https://framagit.org/hubzilla/core into dev
Diffstat (limited to 'vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php')
-rw-r--r--vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php57
1 files changed, 36 insertions, 21 deletions
diff --git a/vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php b/vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php
index 8fd4dd6e2..a122f4052 100644
--- a/vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php
+++ b/vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
namespace League\HTMLToMarkdown\Converter;
use League\HTMLToMarkdown\Configuration;
@@ -8,50 +10,63 @@ use League\HTMLToMarkdown\ElementInterface;
class EmphasisConverter implements ConverterInterface, ConfigurationAwareInterface
{
- /**
- * @var Configuration
- */
+ /** @var Configuration */
protected $config;
- /**
- * @param Configuration $config
- */
- public function setConfig(Configuration $config)
+ protected function getNormTag(?ElementInterface $element): string
+ {
+ if ($element !== null && ! $element->isText()) {
+ $tag = $element->getTagName();
+ if ($tag === 'i' || $tag === 'em') {
+ return 'em';
+ }
+
+ if ($tag === 'b' || $tag === 'strong') {
+ return 'strong';
+ }
+ }
+
+ return '';
+ }
+
+ 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
{
- $tag = $element->getTagName();
+ $tag = $this->getNormTag($element);
$value = $element->getValue();
- if (!trim($value)) {
+ if (! \trim($value)) {
return $value;
}
- if ($tag === 'i' || $tag === 'em') {
+ if ($tag === 'em') {
$style = $this->config->getOption('italic_style');
} else {
$style = $this->config->getOption('bold_style');
}
- $prefix = ltrim($value) !== $value ? ' ' : '';
- $suffix = rtrim($value) !== $value ? ' ' : '';
+ $prefix = \ltrim($value) !== $value ? ' ' : '';
+ $suffix = \rtrim($value) !== $value ? ' ' : '';
+
+ /* If this node is immediately preceded or followed by one of the same type don't emit
+ * the start or end $style, respectively. This prevents <em>foo</em><em>bar</em> from
+ * being converted to *foo**bar* which is incorrect. We want *foobar* instead.
+ */
+ $preStyle = $this->getNormTag($element->getPreviousSibling()) === $tag ? '' : $style;
+ $postStyle = $this->getNormTag($element->getNextSibling()) === $tag ? '' : $style;
- return $prefix . $style . trim($value) . $style . $suffix;
+ return $prefix . $preStyle . \trim($value) . $postStyle . $suffix;
}
/**
* @return string[]
*/
- public function getSupportedTags()
+ public function getSupportedTags(): array
{
- return array('em', 'i', 'strong', 'b');
+ return ['em', 'i', 'strong', 'b'];
}
}