Name: fbmarkdown
Owner: HipHop Virtual Machine
Description: Pure-Hack implementation of GitHub Flavored Markdown, based on the specification at https://github.github.com/gfm/
Created: 2017-12-20 04:43:39.0
Updated: 2018-05-10 17:35:36.0
Pushed: 2018-05-10 17:35:34.0
Homepage: null
Size: 264
Language: Hack
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
FBMarkdown is an extensible parser and renderer for GitHub Flavored Markdown, written in Hack.
It is used to render the Hack and HHVM documentation.
For docs.hhvm.com, we wanted:
Originally, the Ruby GFM pipeline was the best fit; over time, we started to want to:
FBMarkdown exists to address all of these goals.
hhvm composer.phar require facebook/fbmarkdown
namespace Facebook\Markdown;
tion render(string $markdown): string {
st = Markdown\parse(new Markdown\ParserContext(), $markdown);
tml = (new Markdown\HTMLRenderer(
new Markdown\RenderContext()
->render($ast);
turn $html;
For complete compatibility with GitHub Flavored Markdown, support for embedded HTML must be enabled; it is disabled by default as a security precaution.
= (new Markdown\ParserContext())->enableHTML_UNSAFE();
= Markdown\parse($ctx, $markdown);
If you are re-using contexts to render multiple independent snippets, you will need to call ->resetFileData()
on the context.
Facebook\Markdown\UnparsedBlocks
namespace convert
markdown text to a tree of nodes representing the block structure of
the document, however the content of the blocks is unparsed.Facebook\Markdown\Inlines
namespace.Facebook\Markdown\Blocks
namespace are used to
represent the fully parsed AST - blocks and Inlines.The AST is recursively walked, emitting output for each note - e.g. the HTML renderer produces strings.
There are 2 main ways to extend FBMarkdown: extending the parser, and transforming the AST.
Extend Facebook\Markdown\Inlines\Inline
or a subclass, and pass your classname to
$render_ctx->getInlineContext()->prependInlineTypes(...)
.
There are then several approaches to rendering:
Facebook\Markdown\RenderableAsHTML
interfaceFacebook\Markdown\Inlines\InlineSequence
, then you won't need to extend the renderer.You will need to implement the Facebook\Markdown\UnparsedBlocks\BlockProducer
interface, and pass your classname
to $render_ctx->getBlockContext()->prependBlockTypes(...)
.
There are then several approaches to rendering:
Block
, and add support for it to a custom rendererBlock
, and make it implement the Facebook\Markdown\RenderableAsHTML
interfaceFacebook\Markdown\Blocks\BlockSequence
Facebook\Markdown\Blocks\InlineSequenceBlock
Extend Facebook\Markdown\RenderFilter
, and pass it to $render_ctx->appendFilters(...)
.
The Hack and HHVM documentation uses most of these approaches; see:
FBMarkdown is MIT-licensed.
FBMarkdown may contain third-party software; see third_party_notices.txt for details.