Answer the question
In order to leave comments, you need to log in
How to parse inner text in your AbstractInlineParser parser for CommonMark?
I'm making an extension for CommonMark for strikethrough text. But it is not clear how to disassemble the insides. Those. this line should be displayed as a strikethrough, but so that the letters "rive" are displayed in bold. I can't figure out how to do it.
--Hey--
use League\CommonMark\InlineParserContext;
use League\CommonMark\Inline\Element\Text;
use League\CommonMark\Inline\Parser\InlineParserInterface;
/**
* This is the Underline parser class.
*
* @author Shabanov Valera <dev@shasoft.com>
*/
class UnderlineParser implements InlineParserInterface
{
/**
* Create a new parser instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Get the characters that must be matched.
*
* @return string[]
*/
public function getCharacters(): array
{
return ['-'];
}
/**
* Parse a line and determine if it contains an emoji.
*
* If it does, then we do the necessary.
*
* @param \League\CommonMark\InlineParserContext $inlineContext
*
* @return bool
*/
public function parse(InlineParserContext $inlineContext): bool
{
$cursor = $inlineContext->getCursor();
$saved = $cursor->saveState();
$cursor->advance();
$handle = $cursor->match('/^-(.*)--/');
if (!$handle) {
$cursor->restoreState($saved);
return false;
}
$inline = new UnderlineElement;
$inlineContext->getContainer()->appendChild($inline);
$inline->appendChild(new Text(substr($handle, 1, -2))); ????
return true;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question