These days I have been playing around more with a node.js project I am familiar with called marked. This is a package that can be used to parse markdown into html, in addition it is possible to define a custom renderer that can be used to render out plain text, or some other standard other than html. In any case it is a great little package for doing that sort of thing, so it’s worth a post for sure.
I assume that you know the basics when working with an npm package, but even so you might still want to know the name of the package to feed to npm right? So here it is:
Once installed in a new project folder I made an index.js file and did this:
Will give me the following when called from the CLI
There are some npm projects that can be used to do this such as remove-markdown, but it is possible to format the output of marked in many different ways, including plain text, buy writing a custom render.
One step in parsing to plain text is to just render the text of a hyper link, and not add an anchor element in the output.
So here I am making a custom render that renders links differently, I could have it just render the text, or do anything I want really. As You would expect this can be done for a number of elements, including paragraph, and heading elements.
Rendering to plain text, or in any manner that I want is just a matter of overwriting the render methods by passing a custom renderer.
For any method not specified the hard coded method will be used resulting in html being rendered. The full list of methods can be found in the readme
Marked is a great project that has helped me a great deal with getting into text processing. I will update, and expand on this post as I work more with the current project I am working on now that makes use of marked.