-
-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add newer GFM features #1012
Comments
Thanks for the suggestion! Unfortunately, those features aren't actually part of the GFM spec: github/cmark-gfm#350 It's some kind of custom post-processing that GitHub does. I can certainly understand how parity with GitHub.com could be useful but without a spec to follow it's difficult to ensure we are handling every possible edge case the same exact way. Therefore, it's unlikely that we'll incorporate that into this library. But if you find (or create) an extension for these we'd be happy to link to it! |
I think they might be in the future, they're considered "beta" right now. @colinodell, I built a rough working prototype of this. Any interest including in this repo? If not, no problem, I can release as a separate package. final class GFMNotesRenderer implements NodeRendererInterface
{
private const NOTE_TYPES = [
'NOTE',
'TIP',
'IMPORTANT',
'WARNING',
'CAUTION',
];
private BlockQuoteRenderer $baseRenderer;
public function __construct()
{
$this->baseRenderer = new BlockQuoteRenderer();
}
public function render(Node $node, ChildNodeRendererInterface $childRenderer)
{
if (!$parsed = $this->parseBlockQuote($node)) {
return $this->baseRenderer->render($node, $childRenderer);
}
[$textNode, $type] = $parsed;
$textNode->detach();
$p = new Paragraph();
$p->data->set('attributes', ['class' => 'markdown-note-label']);
$p->appendChild(new Text(ucfirst($type)));
$node->prependChild($p);
$node->data->set('attributes', ['class' => sprintf('markdown-note markdown-note-%s', $type)]);
return $this->baseRenderer->render($node, $childRenderer);
}
/**
* @return array{0:Text,1:string}|null
*/
private function parseBlockQuote(Node $node): ?array
{
$textNode = $node->firstChild()?->firstChild();
if (!$textNode instanceof Text || !preg_match('#^\[!([A-Z]+)]$#', $textNode->getLiteral(), $matches)) {
return null;
}
$type = $matches[1];
if (!in_array($type, self::NOTE_TYPES, true)) {
return null;
}
return [$textNode, strtolower($type)];
}
} |
That's awesome!
I'm hesitant to include this here right now because:
But if you do release it as a separate package I'd be happy to link to it from the README and/or docs to help other users find it! (Sorry for the delayed response here) |
Description
GitHub added a few new features to GFM, like alert blocks or inline color display. The
GithubFlavoredMarkdownConverter
should take these into account and add corresponding identifiers (i.e. CSS classes) to these elements to be able to style them accordingly. This is necessary to render markdown files pulled from GitHub as authentically as possible.Example
For example, this:
should render like this:
Note
This is a note
I'm
#0000FF
da ba dee...Did this project help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: