HtmlInline didn't render the HTML tag. #657
-
i tried to create custom extension to render here my sample code to render custom tag to iframe: <?php
namespace App\Markdown\Extensions\Vimeo;
use League\CommonMark\Inline\Element\HtmlInline;
use League\CommonMark\Inline\Element\Link;
use League\CommonMark\Inline\Element\Text;
use League\CommonMark\Inline\Parser\AbstractInlineParser;
use League\CommonMark\InlineParserContext;
class VimeoParser extends AbstractInlineParser
{
/**
* @return string[]
*/
public function getCharacters()
{
return ['@'];
}
/**
* @param InlineParserContext $inlineContext
*
* @return bool
*/
public function parse(InlineParserContext $inlineContext)
{
$cursor = $inlineContext->getCursor();
// The @ symbol must not have any other characters immediately prior
$previousChar = $cursor->peek(-1);
if ($previousChar !== null && $previousChar !== ' ') {
// peek() doesn't modify the cursor, so no need to restore state first
return false;
}
// Save the cursor state in case we need to rewind and bail
$previousState = $cursor->saveState();
// Advance past the @ symbol to keep parsing simpler
$cursor->advance();
// Parse the handle
$handle = $cursor->match('/vimeo\((\d+)\)/');
if (empty($handle)) {
// Regex failed to match; this isn't a valid Image handle
$cursor->restoreState($previousState);
return false;
}
$vimeoId = preg_replace('/[^0-9]+/', '', $handle);
$inlineContext->getContainer()->appendChild(new HtmlInline($this->render($vimeoId)));
return true;
}
/**
* @param $vimeoId
*
* @return string
*/
protected function render($vimeoId)
{
return '<iframe src="https://player.vimeo.com/video/'. $vimeoId .'?title=0&byline=0" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
}
} anyone can explain or give solution? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Are you sure the |
Beta Was this translation helpful? Give feedback.
-
yes, i have tried with simple |
Beta Was this translation helpful? Give feedback.
-
@muhghazaliakbar By investigating my issue further (#285) I discovered a lot more on how the library actually works. You can't render an I suggest you do the same as I did using a custom Block Element, Block Parser & Block Renderer. |
Beta Was this translation helpful? Give feedback.
-
@wouterds can you show me you're |
Beta Was this translation helpful? Give feedback.
-
Closing due to inactivity. |
Beta Was this translation helpful? Give feedback.
@muhghazaliakbar By investigating my issue further (#285) I discovered a lot more on how the library actually works. You can't render an
HtmlInline
element directly from an Inline Parser.I suggest you do the same as I did using a custom Block Element, Block Parser & Block Renderer.