ParseMark.js - A lightweight JavaScript library for parsing Markdown metadata and content separately

Sh Raj - Feb 2 - - Dev Community

ParseMark.js

A lightweight JavaScript library for parsing Markdown metadata and content separately

License

GitHub logo SH20RAJ / ParseMark

A lightweight JavaScript library for parsing Markdown metadata and content separatly

ParseMark.js

A lightweight JavaScript library for parsing Markdown metadata and content separately

Documentation

License npm version Visitors

Installation

Using npm

npm install parsemarkjs
Enter fullscreen mode Exit fullscreen mode

Import

// import ParseMark from './ParseMark.module.js'; // if you have downloaded the js file
import ParseMark from 'parsemarkjs';
Enter fullscreen mode Exit fullscreen mode

Using CDN

Include the following script tag in your HTML file:

<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/ParseMark@main/ParseMark.js"></script>
Enter fullscreen mode Exit fullscreen mode

Usage

Constructor

const markdown = `
---
title: "Sample Post"
tags: javascript, library, markdown
datePublished: Fri, 04 Feb 2024 12:00:00 GMT
---

# Sample Post

This is a sample post content.
`;

const parser = new ParseMark(markdown);
Enter fullscreen mode Exit fullscreen mode

getMetadata()

const metadata = parser.getMetadata();
console.log('Metadata:', metadata);
Enter fullscreen mode Exit fullscreen mode

getRawMetadata()

const rawMetadata = parser.getRawMetadata();
console.log('Raw Metadata:', rawMetadata);
Enter fullscreen mode Exit fullscreen mode

getContent()

const content = parser.getContent();
Enter fullscreen mode Exit fullscreen mode

Installation

Using npm

npm install parsemarkjs
Enter fullscreen mode Exit fullscreen mode

Using CDN

Include the following script tag in your HTML file:

<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/ParseMark@main/ParseMark.js"></script>
Enter fullscreen mode Exit fullscreen mode

Usage

Constructor

const markdown = `
---
title: "Sample Post"
tags: javascript, library, markdown
datePublished: Fri, 04 Feb 2024 12:00:00 GMT
---

# Sample Post

This is a sample post content.
`;

const parser = new ParseMark(markdown);
Enter fullscreen mode Exit fullscreen mode

getMetadata()

const metadata = parser.getMetadata();
console.log('Metadata:', metadata);
Enter fullscreen mode Exit fullscreen mode

getRawMetadata()

const rawMetadata = parser.getRawMetadata();
console.log('Raw Metadata:', rawMetadata);
Enter fullscreen mode Exit fullscreen mode

getContent()

const content = parser.getContent();
console.log('Content:', content);
Enter fullscreen mode Exit fullscreen mode

Example Output

Screenshot 2024-02-02 at 3 14 25 PM

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .