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

md-export

v1.0.5

Published

Customizable parse + convert text

Downloads

8

Readme

md-export

md-export can convert content between formats. It comes with parsers and template for converting Wordpress XML to Markdown but you can easily specify your own.

Quick start

# Generates frontmatted .md files of wordpress posts
npx md-export wp-export.xml --download-images

Installation

yarn global add md-export

Usage

# Convert Wordpress xml to markdown
md-export export.xml

# Download images references in text
md-export export.xml --download-images

# Using your own output template
md-export export.xml --template=my-template.md

# ...or your own parser
md-export anything.json --parser=my-json-parser.js

Generated files, and accompanied images scraped from the post are found in the output folder (default: output).

Instructions for exporting your information from WordPress can be found here.

Options

md-export <input-file> [args]

Options:
  --version              Show version number                           [boolean]

  -d, --download-images  Downloads images references to post folder.
                                                      [boolean] [default: false]

  --debug                Log for debug purposes       [boolean] [default: false]

  -f, --folder-format    Format of individual post folder name.
                                                  [default: "yyyy-mm-dd-"slug""]
  -o, --output-dir       Folder in which to put posts        [default: "output"]

  -i, --filter-images    Regex filter for which linked images to download and
                         replace urls.
  [default: "(?:src="(http[^"]*?)")|(?:href="(http[^"]*?(?:\.(?:apng|bmp|gif|cur
                                |ico|jpg|jpeg|jfif|pjpeg|pjp|png|svg|webp))))""]

  -p, --parser           Which parser to use for parsing input file.
                                            [default: "./parsers/wordpress-xml"]

  -s, --filter-slug      Specify post slug if wish to convert a single post

  -t, --template         Which template to use for generating files.
                                              [default: "./templates/gatsby.md"]

  -h, --help             Show help                                     [boolean]

Examples:
  md-export wordpress.xml     Generates markdown files based on wordpress xml export
  md-export wordpress.xml -d  Downloads linked images (hosted on same domain)

Post output folder

Each post is put in an own individual folder.

/2018-11-30-how-to-markdown/index.md

Its folder name can be specified with --folder-format=YOUR-FORMAT

Default: yyyy-mm-dd-"slug"

Note that quotes are required to surround text that should not be formatted as date.

Replaced values are:

  • author: The author that created the post
  • slug: The url slug name of the post

The rest is formatted as dates, using dateformat.

Images

All linked images in the original post from the same domain are downloaded and put in the folder belonging to the related markdown file, when -d is used

/2018-11-30-how-to-markdown/index.md
/2018-11-30-how-to-markdown/image-for-the-post.jpg
/2018-11-30-how-to-markdown/another-image.jpg

You can download all images to a shared folder by specifying -g=./public/images.

/2018-11-30-how-to-markdown/index.md
/public/images/image-for-the-post.jpg
/public/images/another-image.jpg

By default, we download all links from img src=, and all linked images a href="path to image" that resides within the same domain as the post.

This can be changed with --filter-images=YOUR-REGEX

These URLs are also changed in the content of the original data.

Templates

By default, we use a template of this format

---
title: "{{ title }}"
date: {{ date }}
image: {{ image }}
tags: {{ tags }}
author: {{ author }}
status: {{ status }}
---

{{ content }}

Placeholders, e.g. {{ title }}, are replaced with the data parsed from the input file.

The template used can be changed with --template=my-file.md

Available variables are:

  • author: The author of the post
  • content: The markdown generated body of the post
  • html: The body of the post, in HTML.
  • date: The post date formatted as yyyy-mm-dd
  • slug: The url slug of the original post
  • title: The title of the post
  • image: The featured image of the article

Parsing other inputs

Parsers can be found in in the source code. These contain logic for parsing a file into a structured format. You can add override the parser and specify your own with --parser=YOUR-PARSER.

If you create your own parser, it should default export a function that accepts path of file, and returns a list of an objects. It must return an array of items, where each item should have the following keys:

  • slug: A slug of the item
  • date: date (optional)
  • content: Content as HTML (optional)

Note: You can also add more keys. These will be passed on as is to be reused in the template.