Open-Sourcing Regular Expressions for Markdown Syntax Module by@arthur.tkachenko

Open-Sourcing Regular Expressions for Markdown Syntax Module

Arthur Tkachenko describes this process of open-sourcing a npm package for working with regular expressions: https://github.com/atherdon/markdown-to-email
image

This Slogging thread by Arthur Tkachenko and Limarc Ambalina occurred in slogging's official #programming channel, and has been edited for readability. πŸ€– πŸ€– πŸ€–

πŸ’š 1
Arthur TkachenkoSep 28, 2021, 4:28 PM

While working on https://github.com/atherdon/markdown-to-email repository, we created and adapted a few cool things that I want to share with others.

Intro: "I don't like a lot to start a new project from scratch."

So I'm usually trying to use GitHub search and see what was done by more experienced and crazy developers.

I find a number of repositories that were doing similar things(parsing markdown). But for different reasons, you can't just fork them and make that code work as necessary. So we "steal" some cool implementations and then rewrite them for our needs.

We have a lot of iterations, and at some point, I realize that every project that was doing a similar parsing for markdown syntax used regex`es. But they(RegEx`es) were always highly mixed in their code. long code. smelly code.

I was like: "I don't want to keep it all in one place. It's just eating space in my brain. It's not easy to test, etc, etc"
and if you know about regular expressions, you probably aware about a lot of memes

image
image
image

---

image

Step Zero: other developers were creating a list of constants and put them into their files.
we did it too.

Step One: I move out a lot of constants that were representing RegEx strings into a separate file and just import it. fancy!

Step Two: move all constants into the package folder and try to create a separate npm package, using Rollup.

Module structure with Rollup config and a few js files is very simple. Another huge plus you can separate your tests, which is necessary for the future. and I like that it's very independent and doing only one thing. nothing more. you can see a structure below

image

inside "src" i have few files with regular expressions. one file was related to storing default markdown tags that can be used in other projects. another file was related to custom tags that we "invented" for our own needs.

I also have a separate file for lists only. lists in markdown syntax are pure madness. they should be covered with more tests.

image

Step Three: I realize that I want to contribute something to the world and moved default tags into a separated npm module and a separate GitHub repository. For sure, it's a small input, but nobody did it before.
GitHub link is here: https://github.com/atherdon/markdown-regex
and you can install it -

yarn add markdown-regex

and I'm happy to see it on npm(while it's not indexed well, yet): https://www.npmjs.com/package/markdown-regex

image

Oops, looks like I didn't move tests into a new repository πŸ™‚ time to do the next release πŸ™‚
Back to the Internet!

Limarc AmbalinaSep 29, 2021, 6:39 AM

Looks like you are keeping busy ! 😎

Read moreΒ slogging posts:

react to story with heart
react to story with light
react to story with boat
react to story with money
L O A D I N G
. . . comments & more!