Conversation
Add a new optional converter `StrikethroughConverter`, mention it in the readme and add tests for it
| ### Conversion options | ||
|
|
||
| > [!CAUTION] | ||
| > [!CAUTION] |
There was a problem hiding this comment.
Sorry about this change, but PHPStork wouldn't let me revert this 😅
|
@BentiGorlich Thank you, but @melroy89 Do you have any thoughts on when this will be merged? |
|
Well it might be deprecated, but that doesn't mean that it isn't used anymore. The issue we received about the parsing problem contained the |
although I approved it. I don't have merge rights on this repo. Better ask @colinodell |
|
please merge this @colinodell |
|
Incorrect implementation. EmphasisConverter exists for this purpose. Your code loses flexible configuration settings. |
How would I solve this? And what settings are lost? |
@BentiGorlich I think you need to see the EmphasisConverter, not sure should merge into it or keep them separated here's my own implementation for my project class StrikethroughConverter implements ConverterInterface, ConfigurationAwareInterface
{
public const STYLE_NAME = 'strikethrough_style';
/** @var Configuration */
protected $config;
protected function getNormTag(?ElementInterface $element): string
{
if ($element !== null && ! $element->isText()) {
$tag = $element->getTagName();
if (in_array($tag, $this->getSupportedTags())) {
return 'del';
}
}
return '';
}
public function setConfig(Configuration $config): void
{
$this->config = $config;
}
public function convert(ElementInterface $element): string
{
$tag = $this->getNormTag($element);
$value = $element->getValue();
if (! \trim($value)) {
return $value;
}
$style = $this->config->getOption(self::STYLE_NAME, '~~');
$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 <del>foo</del><del>bar</del> 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 . $preStyle . \trim($value) . $postStyle . $suffix;
}
/**
* @return string[]
*/
public function getSupportedTags(): array
{
return ['del', 'strike', 's'];
}
} |
Add a
StrikethroughConverterwhich converts<strike>Some Text</strike>->~~Some Text~~<del>Some Text</del>->~~Some Text~~