DEV Community

Rafi
Rafi

Posted on

2 3

Markdown like syntax parser

Sometimes you want markdown like syntax but not exact markdown specification. I build a really tiny markdown like syntax parser that you can use out of box or use the functions it exposes to write a custom markdown parser

you can install the package using npm or yarn

$ npm i pico-markdown-parser
Enter fullscreen mode Exit fullscreen mode

Simple usage

import pico from "pico-markdown-parser";

const htmlOutput = pico(`
  # Hello

  This is a sample text!!
`);
Enter fullscreen mode Exit fullscreen mode

Building your own parser

This parser is composed of many small parsers you can import those small parsers from the library and put them together in ways you see fit (like Lego pieces).

import {
  choice, 
  many,
  heading,
  bold,
  anything 
 } from "pico-markdown-parser";

// This new parser now supports only bold and heading
const parser = (input) =>
  many(choice([heading, bold, anything]))
    .run(input)
    .result.join("");

const htmlOutput = parser(`
  # Hello

  This is a **sample** text!!
`);

Enter fullscreen mode Exit fullscreen mode

If the small parsers it gives does not suit your need you can even write your own parser and combine it. This parser is based on arcsecond

Here is the repo. PR's are welcomed !!!

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more