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_parser

v1.3.0

Published

Parser for markdown

Downloads

2

Readme

Use in Node.js

Please note, that the parser isn't complete and still in progress! It's a part of a code competition ;-)

npm install md_parser

Use as command line tool (CLI)

npm install md_parser -g

CLI Usage

md_parser <source> <outputFile>
  1. The 1st argument (source) is required. If it is a file, the file will be read.
  2. The 2nd argument is optional. If it's given, it will be handled as an output file. If it's not given, the result will be printed in console.

Reference

Markdown Parsing Process

The parser parses the following elements in this way:

  • Bold text **Bold**
  • Italic text *Italic*
  • Striked text ~~Striked~~
  • Paragraphs (Text that is seperated with line breaks)
  • Lists (a sub list needs two spaces) * List item
    • Unsorted lists (circular) * Item
    • Sorted lists (numeric) 1. Item
    • Alphabetic Lists lower and upper (lower/upper-alpha) a. Item / A. Item
    • Roman Lists (upper-roman) I. Item
  • Tables (Table Syntax of Github Markdown)
  • Code Blocks (inline <code></code> and blocked <pre><code></code></pre>)
  • Links [Link Text](http://maurice-conrad.eu)
  • Images with optional width & height ![Image Name](https://image-url.com/image.png){width,height} (Link syntax with an ! prefix)
  • Abbreviations ?[This is an Abbreviation](I meant this!) (Link syntax with an ? prefix)
  • iFrames $[Frame Title](http://maurice-conrad.eu) (Link syntax with an $ prefix)
  • Details
    => Summary
       Detailed information

List parsing

Please make sure that the lists will all be parsed as <ul> containing the specific list style as CSS rule. Why? Because of support for untypically lists like alphabetic and roman.

Require

const markdown = require('md_parser');
// Returns the following
{
  parse: [Function],
  rules: [Array]
}

API

The md_parserinstance returns the method parse and the array rules. This array contains the default parsing rules and can be customized. You can see more below.

Parse

const markdown = require('md_parser');

var markdownStr = "# Title 1\n## Title 2\n\nParagraph"; // The string containing the markdown context

markdown.parse(markdownStr, {
  //rules: [], // Custom parsing rules. Don't use by default
  validDocument: true, // Wether the returned string is a valid HTML document with DOCTYPE, head, body etc.
  pretty: true, // Wether the result is pretty printed
  disallowedFeatures: [ // Disallowed feature classes e.g. 'github', 'default', '3rd-party'... (Used to prevent bugs with not official features like abbreviations, iframes, details). The classes of a feature are defined its object in the rules array
    //"html5",
    //"paragraph"
  ]
});

Parsing Rules

The parsing rules are an array with some regular expressions and functions.

The default rules are located in the file default-rules.js. These rules are sometimes just regular expressions and sometimes more complex functions. The md_parser instance contains such an array with the default rules. If you call the parse method and you don't pass a custom array with rules as option, the rules array of the md_parser instance will be used.

Parsing Rules Reference

A rules array contains objects as rules. Every object represents one markdown element. Have a look at the general structure of a rules array.

// Rules array
[
  {...}, // Some other rules
  {
    name: "name-of-element", // The name of the element.
    classes: ["default", "my-class", "special-feauture-class"],
    query: '(.*)', // A regular expression string
    replace: '<myReplacement>$1</myReplacement>', // The replacement for the regex
    parse: function(str) {
      // Special parsing function that returns the parsed string
      return str;
    }
  },
  {...} // Some other rules
]
Example

You don't understand it? For example, let's have a look at the parsing rule for a strong tag:

{
  name: "bold",
  query: '\\*{2}([^\\*]*)\\*{2}', // Queries bold text
  replace: '<strong>$1</strong>'
}

As you can see, a special parse function isn't required in this case. In some other cases there is no regular expression but just a special parse function within the rule object.