Closes #353 - Created a way to compile markdown to text

This commit is contained in:
Chris Cowan 2014-09-22 17:05:00 -07:00
parent f936dd403c
commit 47b353fbcc
5 changed files with 64 additions and 12 deletions

View file

@ -23,11 +23,14 @@
"grunt-replace": "^0.7.9",
"grunt-run": "^0.2.3",
"grunt-saucelabs": "~8.3.2",
"html-entities": "^1.1.1",
"http-proxy": "~1.1.4",
"husky": "~0.6.0",
"istanbul": "~0.2.4",
"load-grunt-config": "~0.7.0",
"lodash": "~2.4.1",
"marked": "^0.3.2",
"marked-text-renderer": "^0.1.0",
"mkdirp": "^0.5.0",
"mocha": "~1.20.1",
"mocha-screencast-reporter": "~0.1.4",

View file

@ -14,6 +14,7 @@ module.exports = function (grunt) {
'warble',
'replace:dist',
'copy:dist',
'compile_dist_readme',
'chmod_kibana',
'compress:build_zip',
'compress:build_tarball'

View file

@ -0,0 +1,60 @@
var marked = require('marked');
var Promise = require('bluebird');
var join = require('path').join;
var TextRenderer = require('marked-text-renderer');
var _ = require('lodash');
var fs = require('fs');
var entities = new (require('html-entities').AllHtmlEntities)();
var readFile = Promise.promisify(fs.readFile);
var writeFile = Promise.promisify(fs.writeFile);
TextRenderer.prototype.heading = function (text, level, raw) {
return '\n\n' + text + '\n' + _.map(text, function () { return '='; }).join('') + '\n';
};
var process = function (input) {
var output = input.replace(/<\!\-\- [^\-]+ \-\->/g, '\n');
output = marked(output);
return entities.decode(output);
};
module.exports = function (grunt) {
grunt.registerTask('compile_dist_readme', function () {
var done = this.async();
var root = grunt.config.get('root');
var build = grunt.config.get('build');
var srcReadme = join(root, 'README.md');
var distReadme = join(build, 'dist', 'README');
var srcLicense = join(root, 'LICENSE.md');
var distLicense = join(build, 'dist', 'LICENSE');
marked.setOptions({
renderer: new TextRenderer(),
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
});
readFile(srcReadme, 'utf-8')
.then(function (data) {
return writeFile(distReadme, process(data.toString()));
})
.then(function () {
return readFile(srcLicense, 'utf-8');
})
.then(function (data) {
return writeFile(distLicense, process(data.toString()));
})
.then(done)
.catch(done);
});
};

View file

@ -46,14 +46,6 @@ module.exports = function (grunt) {
dist: {
options: { mode: true },
files: [
{
src: '<%= root %>/LICENSE.md',
dest: '<%= build %>/dist/LICENSE.md'
},
{
src: '<%= root %>/README.md',
dest: '<%= build %>/dist/README.md'
},
{
expand: true,
cwd: '<%= build %>/kibana/',

View file

@ -11,10 +11,6 @@ module.exports = function (grunt) {
]
},
files: [
{
src: [join(src, 'server', 'README.md')],
dest: join(build, 'dist', 'README.md')
},
{
src: [join(src, 'server', 'bin', 'kibana.sh')],
dest: join(build, 'dist', 'bin', 'kibana')