npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parcel-plugin-markdown-it

v1.0.0

Published

Parcel plugin to generate HTML and metadata dictionary from Markdown files

Downloads

24

Readme

This parcel plugin reads Markdown files and convert them to HTML using markdown-it package.

This HTML is stored in a variable named html.

Plugin also reads Markdown metadata and it stores it in a variable named meta.

import { meta, html } from "./README.md";

CircleCI

Getting started

It uses regular Parcel plugin system, so you only have to install the plugin in your project.

If you are using yarn:

yarn add parcel-plugin-markdown-it --dev

If you are using npm:

npm install parcel-plugin-markdown-it --save-dev

This command just installs parcel-plugin-markdown-it in your node_modules folder and adds it to development dependency section in package.json:

"devDependencies": {
    "parcel-plugin-markdown-it": "^0"
}

Simple Example

For this example we will use a README.md with following content:

---
layout: post
title: Example title
---

This is another post, you can find more at https://google.es

You can import a Markdown file like any regular Javascript module.

Import

import { meta, html } from "./README.md";

console.log('meta: ', meta);
console.log('html: ', html);

You will see following output in console:

meta: 
{title: "Example title", layout: "post"}
html: 
"<p>This is another post, you can find more at <a href=\"https://google.es\">https://google.es</a></p>"

Require

const md = require("./README.md");

console.log('md: ', md);

You will get the following output in console:

md: 
{
    meta: {title: "Example title", layout: "post"},
    html: "<p>This is another post, you can find more at <a href=\"https://google.es\">https://google.es</a></p>"
}

Enable code blocks with syntax highlight

Install the package 'markdown-it-highlightjs'

npm install --save-dev markdown-it-highlightjs

and include the required css styles in your pages

import 'highlight.js/styles/default.css'

Now code blocks embedded in markdown document will be rendered with syntax highlight

Index all Markdown files in a directory

This feature is still not working properly until https://github.com/parcel-bundler/parcel/issues/112 in ParcelJs is fixed.

I will explain how this is currently implemented, but this feature most likely will evolve.

const index = require("./index.blog");

for (const post of index) {
    const dir = post.dir || '.';
    const postPath = dir + '/' + post.base;
    import(postPath)
        .then(imported => console.log(imported))
        .catch(error => console.error(error));
}

Let's say index.blog file content is as follows:

{
    "title": "My Blog",
    "postsFolder": "/home/my/posts",
    "author": "[email protected]"
}

Following code snippet is supposed to lazy load al the Markdown files in /home/my/posts and print them to console.

Expected output:

[
    {
        html: "<p>First post found in folder</p>",
        meta: { 
            author: "[email protected]",
            title: "Post 1"  
        }
    },
    {
        html: "<p>Second post found in folder</p>",
        meta: { 
            layout: "micro",
            title: "Post 2"  
        }
    },
    ...
]

This feature would ease the implementation of a simple static site generator.

When this feature is properly working, I will most likely extend it to support static site generation.