Today I learned that plugin-based architectures are beautiful, extendible, and nigh impossible to figure out. The more you dig the less you know where anything happens.
I built my first remark plugin. #200wordsTIL
Remark is that wonderfully extensible markdown parser powering @gatsbyjs MDX @freecodecamp and others.
Remark is built by the Unified collective over at https://unified.js.org
Unified, also, is a library. Or maybe it's a standard? Remark seems to be a specific implementation of Unified.
See what I mean? It's confusing. Where does anything 𝘢𝘤𝘵𝘶𝘢𝘭𝘭𝘺 happen?
Anyway, remark takes markdown and turns it into mdast. A markdown abstract syntax tree.
Everything else happens with plugins. Many exist.
My plugin finds **bold** and _italic_ nodes and turns them into utf8 characters. Found an package for that, but had to copy pasta 😞
Unified has a utility that makes the visitor pattern a breeze 👉 visit() calls your functions on just the nodes you care about. Wonderful 👌
Livecoded it all 👇