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

front-matter-markdown

v0.4.5

Published

get the config and toc object from the markdown string.

Downloads

9,789

Readme

front-matter-markdown npm

Build Status Code Climate Test Coverage downloads license

Get the config object from a markdown string. It will extract configuration from front-matter. And get the directory(contents) from the list of heading TOC/Table Of Content/Summary. It will generate a TOC from the markdown string if the list is empty

Usage

parseMarkdown = require('front-matter-markdown')

markdownStr = """
---
title: this is a title
---

# table of contents

* [Directory](./dir1)
  * [Directory2](/dir2)
* [Directory3](#inline)

# this is a inline heading {#inline}

"""
console.log(JSON.stringify parseMarkdown(markdownStr), null, 1)

the results:

{
 "title": "this is a title",
 "skipSize": 31,
 "ordered": false,
 "contents": [
  {
   "title": "Directory",
   "path": "./dir1",
   "ordered": false,
   "contents": [
    {
     "title": "Directory2",
     "path": "/dir2"
    }
   ]
  },
  {
   "title": "Directory3",
   "path": "#inline"
  }
 ]
}

API

var parseMarkdown = require('front-matter-markdown');
  • parseMarkdown(aMarkdownString, aOptions): parse a markdown string to a plain object.
    • aOptions(Object):
      • content (Boolean): whether extract the markdown content from configuration. defaults to true. it will store the compiled markdown to $compiled too.
        • Note: the content and $compiled attributes are non-enumerable.
      • toc (Boolean): whether extract the directory from the list in the specified heading. defaults to false. the 'directoy' is put into contents attributes.
      • links (Boolean): merge the markdown links label to the result, default to false.
      • heading (String|RegExp|ArrayOf(String)): the toc list in the heading(s) to extract the directory. defaults to ['TOC', 'Table Of Content', 'Summary']
      • headingsAsToc (Boolean|Object): whether generate the directory from the headings of markdown. defaults to false. It will generate the toc if no toc list in the specified heading(toc enabled).
        • maxDepth (Number): Use headings whose depth is at most max depth for generate. defaluts to 3.
        • firstLevel (Number): the first level to generate the directory from the headings of markdown. defaluts to 1.
    • Returns:
      • skipSize Number: the front-matter configuration size if exists
      • content String: the markdown string after removing the front-matter configuration. (available on content is true)
      • $compiled Object: the compiled markdown tree.(available on content is true)
      • contents Object: the directory from the list in the specified heading. (available on toc)

Changes

v0.3

  • markdown inline options to control parser.
    • toc
    • heading: the toc list in the heading section.
    • headingsAsToc
  • setOptionAlias function
  • broken: toc, headingsAsToc options are defaults to false now.
  • add the links option: merge the markdown links label to the result, default to false.
markdownStr = """
  ---
  title: this is a title
  toc: false
  headingsAsToc: false
  heading: Category
  ---
  # Category

  * [Directory](./dir1)
    * [Directory2](/dir2)
  * [Directory3](#inline)

  # this is a inline heading {#inline}

  [linkLabel1]: hi
  [linkLabel2]: url "with title text"
  """
result = parseMarkdown(markdownStr) #= parseMarkdown markdownStr,
                                    #   toc:false
                                    #   headingsAsToc: false
                                    #   heading: 'Category'

License

MIT