<?phpnamespaceLia\Addon\MdBlog\Test;
useLeague\CommonMark\Environment\Environment;
useLeague\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
useLeague\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
useLeague\CommonMark\Extension\CommonMark\Node\Block\IndentedCode;
useLeague\CommonMark\MarkdownConverter;
useSpatie\CommonMarkHighlighter\FencedCodeRenderer;
useSpatie\CommonMarkHighlighter\IndentedCodeRenderer;
classBlogsextends \Taeluf\Tester{
publicfunctionprepare(){
}
publicfunctiontestDocumentHighlightCode(){
//@export_start(Usage.Main)$liaison = new \Liaison();
new \Lia\Addon\CommonMark($liaison);
$liaison->set('lia:blog.use_cache', false); //change to true to use caching$blog_addon = new \Lia\Addon\Blog($liaison, $this->cli->pwd.'/test/blogs');
$response = $liaison->getResponse('/blog/test/header-with-php/', 'GET');
echo$response->content;
//@export_end(Usage.Main)$this->check_contains($response->content);
}
/**
* Mainly intended to test THAT the highlighter is running, rather than to test the specific output of the highlighter
*/publicfunctiontestHighlightCode(){
$liaison = new \Liaison();
new \Lia\Addon\CommonMark($liaison);
$liaison->set('lia:blog.use_cache', false);
$liaison->schedule('RouteResolved',function($route,$response){$response->useTheme=false;});
$blog_addon = new \Lia\Addon\Blog($liaison, $this->cli->pwd.'/test/blogs');
$response = $liaison->getResponse('/blog/test/header-with-php/', 'GET');
## Without the str_replace & WITH a trim() there was a 6 character difference I couldn't spot.# I don't care if there's extra whitespace. This is good enough for me for now.$this->compare(str_replace(' ', '',$this->get_highlighted_html()), str_replace(' ','',$response->content));
echo$response->content;
$this->check_contains($response->content);
}
protectedfunctioncheck_contains($content){
$this->str_contains($content, ['hljs-function', 'language-php hljs php', 'hljs-keyword', 'hljs-title', 'hljs-params', 'hljs-string']);
}
protectedfunctionget_highlighted_html(){
$markdown = file_get_contents($this->cli->pwd.'/test/blogs/test/header-with-php.md');
$environment = new Environment;
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addRenderer(FencedCode::class,
new FencedCodeRenderer());
$environment->addRenderer(IndentedCode::class,
new IndentedCodeRenderer());
$markdownConverter = new MarkdownConverter($environment);
// $this->handleDidPass(true);return$markdownConverter->convertToHtml($markdown).'';
}
}