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

grunt-markdown-extend

v0.0.4

Published

Compile markdown to html. GFM and code highlighting support!

Downloads

11

Readme

grunt-markdown

Build Status

This grunt task takes a set of markdown files and converts them to HTML. It supports GFM with code highlighting. The code highlighting is done using highlight.js.

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with:

npm install grunt-markdown --save-dev

Then add this line to your gruntfile:

grunt.loadNpmTasks('grunt-markdown');

Documentation

Creating a markdown task is simple. For the basic functionality add the following config in your gruntfile:

grunt.initConfig({
  markdown: {
    all: {
      files: [
        {
          expand: true,
          src: 'docs/src/*.md',
          dest: 'docs/html/',
          ext: '.html'
        }
      ]
    }
  }
});

Here is an example config using all of the options:

grunt.initConfig({
  markdown: {
    all: {
      files: [
        {
          expand: true,
          src: 'docs/src/*.md',
          dest: 'docs/html/',
          ext: '.html'
        }
      ],
      options: {
        template: 'myTemplate.jst',
        preCompile: function(src, context) {},
        postCompile: function(src, context) {},
        templateContext: {},
        markdownOptions: {
          gfm: true,
          highlight: 'manual',
          codeLines: {
            before: '<span>',
            after: '</span>'
          }
        }
      }
    }
  }
});

These are the properties that the markdown task accepts:

  • files: This plugin supports use of the files API introduced in Grunt 0.4.0. Files may be specified using any one of the Compact Format, Files Objects Format, or Files Array Format (as in the above example).
  • options: options to be passed to the markdown parser
    • template: If you wish to specify your own html template, use the template option. Include the following line: <%=content%> where you want the compiled markdown inserted in your template
    • markdownOptions: Options passed directly to the markdown parser.
    • preCompile: is run before the markdown is compiled
    • postCompile: is run after the markdown has been compiled
    • templateContext: the default context for template expansion

modifying content with preCompile and postCompile

Sometimes there is a need to modify the markdown content prior to compilation. This is most commonly used to augment the template context with meta data before expanding the html template.

preCompile

This function is run prior to the compilation of md to html. It has the following format:

  function(src, context) {
    //do stuff to src and context
    //optionally return the modified src
  }

postCompile

This function is run after the md has been converted to html. It has the following format:

  function(src, context) {
    //do stuff to src and context
    //optionally return the modified src
  }

templateContext

This object is used to expand your html template. Any data added to this object will be available in the template using the template syntax <%=myAttr%>.

This can also be a function which is expected to return a context object.

markdownOptions

Most markdown options are passed as-is to the marked markdown parser. The only option that is processed prior to compiling the markdown is the highlight option. If you specify 'auto' or 'manual' the task will handle highlighting code blocks for you using highlight.js. If you pass a custom function as the highlight option it will be used to highlight the code.

  • auto: Will try to detect the language
  • manual: will pass the language name from markdown to the highlight function
  • codeLines: specify text that should wrap code lines

License

Copyright (c) 2012-2013 James Morrin Licensed under the MIT license.