Comments (3)
I built a rough working prototype of this.
That's awesome!
Any interest including in this repo? If not, no problem, I can release as a separate package.
I'm hesitant to include this here right now because:
- It's technically not (yet?) part of GFM, so it shouldn't be included as part of our GFM extension
- There's no consensus that GitHub's admonitions should be the "standardized" way to implement them (there are other formats out there)
- There's no spec for this, and reverse-engineering the edge cases around GitHub's implementation doesn't sound like a fun time.
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)
from commonmark.
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!
from commonmark.
Unfortunately, those features aren't actually part of the GFM spec
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)];
}
}
from commonmark.
Related Issues (20)
- Weird glitch with Footnote Extension HOT 3
- Code blocks sometimes don't render first character HOT 1
- Question: Disable some elements HOT 1
- Allow setting attributes without values in Attributes extension HOT 1
- Heading levels HOT 3
- Algolia Search Not Giving Any Results HOT 1
- LinkRenderer always adding `rel="noopener noreferrer"` when opening in new window HOT 4
- Last backslash before a heading/table gets preserved HOT 1
- Delimeter processor doesn't run in links and images HOT 3
- Delimiter processor cannot have a space right after opener and/or before closer HOT 1
- Weird interaction of code block with other block parsers HOT 1
- Exception when setting unordered_list_markers; exception when *not* setting unordered_list_markers HOT 1
- Can it compare two md contents?
- Add support for github admonition HOT 1
- HeadingPermalinkExtension does not percent-encode CJK names, but commonmark does percent-encode CJK URLs
- addRenderer and addExtension inconsistency HOT 2
- HeadingPermalinkRenderer Accessibility HOT 4
- Maximum execution time exceeded in Parser/Cursor.php when processing large base64 string.
- FencedCodePar
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commonmark.