Coder Social home page Coder Social logo

grunt-highlight's Introduction

grunt-highlight

Run highlight.js over files

Getting Started

This plugin requires Grunt.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-highlight --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-highlight');

The "highlight" task

Overview

In your project's Gruntfile, add a section named highlight to the data object passed into grunt.initConfig().

grunt.initConfig({
  highlight: {
    task: {
      options: {
        // Task-specific options go here.
      },
      your_target: {
        // Target-specific file lists and/or options go here.
      }
    }
  }
});

Options

options.lang

Type: Boolean Default value: false

If you know the highlight language, use this.

options.useCheerio

Type: Boolean Default value: true

You target files are HTML and you want to parse over them and highlight code blocks. Turn off for raw code input.

options.selector

Type: Boolean Default value: pre code

This is what cheerio will be looking for as code block in your HTML. Only used when useCheerio is true.

Usage Examples

Default Options

grunt.initConfig({
  highlight: {
    task: {
      options: {},
      files: {
        'dest/out.html': ['src/in.html'],
      }
    }
  }
});

Full Code Files

If you want to highlight an entire file then use the following:

grunt.initConfig({
  highlight: {
    task: {
      options: {
        useCheerio: false,
        lang: 'javascript' // treat the file as a javascript file
      },
      files: {
        'dest/highlighted.html': ['src/bunch-o-javascript.js'],
      }
    }
  }
});

One-to-One Compilation

Sometimes you want to take in a folder of code, and output a folder of highlighted HTML.

highlight: {
  scripts: {
    options: {
      useCheerio: false, // these are pure js files
      lang: 'javascript' // there is no auto-detect for files
    },
    files: [{
      expand: true,
      cwd: 'scripts', // in folder
      src: ['{,*/}*.js'],
      dest: 'html', // out folder
      rename: function(dest, src) {
        // we dont want the output to be .js, make it .html
        return dest + '/' + src.replace(/\.js$/, '.html');
      }
    }]
  }
}

Many Tasks

grunt.initConfig({
  highlight: {
    scripts: {
      options: {
        useCheerio: false,
        lang: 'javascript'
      },
      files: {
        'javascript.html': ['src/script.js']
      }
    },
    styles: {
      options: {
        useCheerio: false,
        lang: 'css'
      },
      files: {
        'stylesheet.html': ['src/style.css']
      }
    }
  }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

(Nothing yet)

License

Copyright (c) 2013 James Doyle. Licensed under the MIT license.

grunt-highlight's People

Contributors

djblue avatar james2doyle avatar jonathan-beebe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.