assemble for HTML parsing or full css/js files.
This was made much easier thanks to the yeoman-gruntplugin project.
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');
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.
}
}
}
});
Type: Boolean
Default value: false
If you know the highlight language, use this.
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.
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.
grunt.initConfig({
highlight: {
task: {
options: {},
files: {
'dest/out.html': ['src/in.html'],
}
}
}
});
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'],
}
}
}
});
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']
}
}
}
});
Check out the project on github.
I'm a full-stack developer, co-organizer of PHP Vancouver meetup, and winner of a Canadian Developer 30 under 30 award. I'm a huge Open Source advocate and contributor to a lot of projects in my community. When I am not sitting at a computer, I'm trying to perfect some other skill.