I've done the following workaround that works for me.
vendor/magento/module-cms/Helper/Wysiwyg/Images.php
...
protected $scopeConfig;
...
public function __construct(
...
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
...
) {
...
$this->scopeConfig = $scopeConfig;
}
...
public function getImageHtmlDeclaration($filename, $renderAsTag = false)
{
$fileurl = $this->getCurrentUrl() . $filename;
/**** WORKAROUND START ****/
$adminUrl = $this->scopeConfig->getValue('admin/url/custom');
$baseUrl = $this->scopeConfig->getValue('web/secure/base_url');
$fileurl = str_replace($adminUrl, $baseUrl, $fileurl);
/**** WORKAROUND END ****/
$mediaUrl = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$mediaPath = str_replace($mediaUrl, '', $fileurl);
$directive = sprintf('{{media url="%s"}}', $mediaPath);
if ($renderAsTag) {
$html = sprintf('<img src="%s" alt="" />', $this->isUsingStaticUrlsAllowed() ? $fileurl : $directive);
} else {
if ($this->isUsingStaticUrlsAllowed()) {
$html = $fileurl; // $mediaPath;
} else {
$directive = $this->urlEncoder->encode($directive);
$html = $this->_backendData->getUrl(
'cms/wysiwyg/directive',
[
'___directive' => $directive,
'_escape_params' => false,
]
);
}
}
return $html;
}
It is not a good idea to modify vendor files, so I've added this into separate extension https://github.com/troublediehard/wysiwyg-custom-admin-workaround