mirror of
https://gh.wpcy.net/https://github.com/ztersinc/freescout-clickup-module.git
synced 2026-04-17 19:22:21 +08:00
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\ClickupIntegration\Transformers;
|
|
|
|
use League\HTMLToMarkdown\ElementInterface;
|
|
use League\HTMLToMarkdown\HtmlConverter;
|
|
use Modules\ClickupIntegration\Transformers\Converters\ImageConverter;
|
|
|
|
/**
|
|
* Custom converter class to proxy HTML to Markdown conversions
|
|
*/
|
|
class MarkdownTransformer extends HtmlConverter
|
|
{
|
|
/**
|
|
* Constructs a new instance
|
|
*
|
|
* @param array $options
|
|
*/
|
|
public function __construct(array $options = [])
|
|
{
|
|
parent::__construct([
|
|
'strip_tags' => true
|
|
] + $options);
|
|
}
|
|
|
|
/**
|
|
* Intercepts markdown conversion to add support for base64 image transformation
|
|
*
|
|
* @param ElementInterface $element
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function convertToMarkdown(ElementInterface $element): string
|
|
{
|
|
$tag = $element->getTagName();
|
|
|
|
if ($tag === 'img') {
|
|
# Custom markdown images to use base64 encoded string
|
|
$markdown = (new ImageConverter())->convert($element);
|
|
} else {
|
|
# Other elements will transform as usual
|
|
$markdown = parent::convertToMarkdown($element);
|
|
}
|
|
|
|
return $markdown;
|
|
}
|
|
}
|