Introduction to league/commonmark

Lead Web Developer for Unleashed Technologies at Unleashed Technologies
Jan. 22, 2016
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
Introduction to league/commonmark
1 of 24

More Related Content

Similar to Introduction to league/commonmark

CommonMark: Markdown Done RightCommonMark: Markdown Done Right
CommonMark: Markdown Done RightColin O'Dell
CommonMark: Markdown done right - Nomad PHP September 2016CommonMark: Markdown done right - Nomad PHP September 2016
CommonMark: Markdown done right - Nomad PHP September 2016Colin O'Dell
Sonar - the ring to rule them allSonar - the ring to rule them all
Sonar - the ring to rule them allSebastian Marek
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracketjnewmanux
WWX 2013  CocktailWWX 2013  Cocktail
WWX 2013 CocktailRaphael Harmel
T5 Oli AroT5 Oli Aro
T5 Oli AroJavier Toledo

More from Colin O'Dell

Demystifying Unicode - Longhorn PHP 2021Demystifying Unicode - Longhorn PHP 2021
Demystifying Unicode - Longhorn PHP 2021Colin O'Dell
Releasing High Quality Packages - Longhorn PHP 2021Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021Colin O'Dell
Releasing High Quality PHP Packages - ConFoo Montreal 2019Releasing High Quality PHP Packages - ConFoo Montreal 2019
Releasing High Quality PHP Packages - ConFoo Montreal 2019Colin O'Dell
Debugging Effectively - ConFoo Montreal 2019Debugging Effectively - ConFoo Montreal 2019
Debugging Effectively - ConFoo Montreal 2019Colin O'Dell
Automating Deployments with Deployer - php[world] 2018Automating Deployments with Deployer - php[world] 2018
Automating Deployments with Deployer - php[world] 2018Colin O'Dell
Releasing High-Quality Packages - php[world] 2018Releasing High-Quality Packages - php[world] 2018
Releasing High-Quality Packages - php[world] 2018Colin O'Dell

Recently uploaded

OutSystems Security Specialization - Study Help DeckOutSystems Security Specialization - Study Help Deck
OutSystems Security Specialization - Study Help DeckFábio Godinho
Fuzzing for CPS Mutation TestingFuzzing for CPS Mutation Testing
Fuzzing for CPS Mutation TestingLionel Briand
Database Storage Engine InternalsDatabase Storage Engine Internals
Database Storage Engine InternalsAdewumiSunkanmi
A Guide to Java Dynamic Proxies and It in CodingA Guide to Java Dynamic Proxies and It in Coding
A Guide to Java Dynamic Proxies and It in CodingMikeConner22
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
OpenAI GPT in Depth - Questions and MisconceptionsOpenAI GPT in Depth - Questions and Misconceptions
OpenAI GPT in Depth - Questions and MisconceptionsIvo Andreev

Introduction to league/commonmark

Editor's Notes

  1. Alright! Today we're going to talk about the PHP League’s CommonMark library But first, a brief introduction of myself
  2. Also JavaScript, C#, and Java OUT: So let’s go ahead and take a look at this Markdown parser
  3. The league/commonmark library At its core, it takes Markdown in and spits HTML out OUT: Now I’ve mentioned the word CommonMark a few times, but what is that?
  4. We’re all familiar with the usual markdown syntax This specification dictates exactly how compliant parsers should handle Markdown input It includes That’s cool, but do we really NEED a spec? Is Markdown really that complicated? Well, let’s look at an example
  5. Straight-forward example of emphasizing text
  6. What happens if we add two asterisks?
  7. Whole string emphasized with nested inner emphasis, as you’d expect Another approach some parsers take is two separate emphasis elements Kinda makes sense What’s really strange and unexpected 3 other ways of parsing this (22%) OUTRO: The CommonMark standard is designed to eliminate this ambiguity so that your Markdown is handled in a logical, predictable fashion
  8. That’s why we’ve adopted this specification for our library
  9. Several integrations for this library built by the community
  10. This project also caters to advanced users…
  11. This project also caters to advanced users… Who need more power, control, and flexibility
  12. We have a URL we want to link to using the standard autolinking syntax Wrapped with a less-than and greater-than sign “A” tag with href and text label of the URL Show how our engine does this behind-the-scenes
  13. Start off with Markdown input Run it through the various sub-parsers which results in an Abstract Syntax Tree
  14. Also known as an AST Tree structure of PHP objects, each representing a certain type of element For easier visualization I’m showing what these PHP objects MIGHT look like if we showed their data as XML Once we’ve got the final AST, we pass that along to the renderers…
  15. …which convert the AST into HTML Now what’s really cool is that…
  16. You can hook into any of these three aspects, adding “your own custom…” Now let’s go back to our autolink example
  17. What if we wanted to add similar autolinking functionality, but for Twitter handles? For example, say we want to enclose the Twitter handle in a similar fashion… which results in a link to that profile page Let me show you how simple it is to add this feature
  18. Simply create a sub-parser 1. Tell the main parser to stop whenever a less-than sign is encountered 2. Cursor is a simple yet powerful wrapper around the current line - Current character position - If the line is indented - Easily advance through that string Match this regular expression Extract just the username from the matched text That’s it! Now the APIs and methods might be unfamiliar, but hopefully you can see how features can be added seemlesly with only a few lines of code
  19. Easy to customize to fit your needs with classes and extension points specifically designed with customization in mind
  20. Things like the cursor are UTF-8-aware Supports Chinese characters, emoji
  21. 94% coverage Including all 613 tests from the CommonMark spec test suite Guaranteed to be compatible with all other CommonMark parsers in other languages
  22. So if you’d like to check it out, you can find the library on Packagist under league/commonmark Installation instructions & documentation can be found Hopefully you find this library useful and can try it out in your next project. Thank you so much!