Markdown is one of the most popular markup languages on the Web. Unfortunately, with no standard specification, every implementation works differently, producing varying results across different platforms. The CommonMark specification fixes this by providing an unambiguous syntax specification and a comprehensive suite of tests. Attendees will learn about this standard and how to integrate the league/commonmark parser into their applications. We will also cover how to add new custom features.
4. COMMONMARK IS…
A strongly defined, highly compatible specification of Markdown.
Written by people from Github, StackOverflow, Reddit, and others.
Spec includes:
Strict rules (precedence, parsing order, handling edge cases)
Specific definitions (ex:“whitespace”,“punctuation”)
616 examples
5. WHY IS IT NEEDED?
*I love Markdown*
<p><em>I love Markdown</em></p>
9. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
10. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
13. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
14. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
21. class TwitterUsernameAutolinkParser extends AbstractInlineParser {
public function getCharacters() {
return ['<'];
}
public function parse(InlineParserContext $inlineContext) {
$cursor = $inlineContext->getCursor();
}
}
32. EXAMPLE 3: CUSTOM RENDERER
class ImageHorizontalRuleRenderer implements BlockRendererInterface {
public function render(...) {
return new HtmlElement('img', ['src' => 'hr.png']);
}
}
34. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
35. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
36. WELL-TESTED
94% code coverage
Functional tests
All 616 spec examples
Library of regression tests
Unit tests
Cursor
Environment
Utility classes
37. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
38. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
39. PERFORMANCE
0 20 40 60 80 100
Parsedown
cebe/markdown
PHP Markdown Extra
league/commonmark
Time (ms)
league/commonmark is ~35-40ms slower
PHP 5.6 PHP 7.0
Tips:
• Choose library based on your needs
• Cache rendered HTML (100% boost)
• Use PHP 7 (50-80% boost)
• Optimize custom functionality
40. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
41. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable
42. STABILITY
Current version: 0.13.3
Conforms to CommonMark spec 0.25
1.0.0 will be released once CommonMark spec is 1.0
No major stability issues
Backwards Compatibility Promise:
No BC breaks to CommonMarkConverter class in 0.x
Other BC breaks will be documented
43. FEATURES
100% compliance with the CommonMark spec
Easy to implement
Easy to customize
Well-tested
Decent performance
(Relatively) stable