protected function Cmark::convertToHtml in Markdown 8.2
Converts Markdown into HTML.
Note: this method is not guaranteed to be safe from XSS attacks. This returns the raw output from the parser itself.
If you need to render this output you should use the \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface::parse() method instead.
@internal
Parameters
string $markdown: The markdown string to convert.
\Drupal\Core\Language\LanguageInterface $language: Optional. The language of the text that is being converted.
Return value
string The raw parsed HTML returned from the parser.
Overrides BaseParser::convertToHtml
See also
\Drupal\markdown\Render\ParsedMarkdownInterface
\Drupal\markdown\Plugin\Markdown\ParserInterface::parse()
File
- src/
Plugin/ Markdown/ Pecl/ Cmark.php, line 34
Class
- Cmark
- Plugin annotation @MarkdownAllowedHtml( id = "commonmark-pecl", ) @MarkdownParser( id = "commonmark-pecl", label = @Translation("CommonMark PECL"), description = @Translation("CommonMark PECL extension using libcmark."), weight = 10, …
Namespace
Drupal\markdown\Plugin\Markdown\PeclCode
protected function convertToHtml($markdown, LanguageInterface $language = NULL) {
try {
if (is_string($markdown)) {
// NOTE: these are functions, not classes.
$node = \CommonMark\Parse($markdown);
return \CommonMark\Render\HTML($node);
}
} catch (\Exception $e) {
// Intentionally left blank.
}
return '';
}