Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

"use strict";

var cp = require( 'child_process' ),
Expand Down Expand Up @@ -73,37 +74,47 @@ module.exports = {
// Append it to the temporary file
fs.appendFileSync( that.tempFile, content );
});
const command = "markdown_py";

// Now, everything is correctly added in the temp file,
// so we can transform everything with markdown_py.
// For this, we need to build up the command.
var command = "markdown_py --output_format='html5' ";

// For this, we need to build up the command.
var command_args = [];
command_args.push("--output_format=html5")
if ( this.toc ) {
command += '-x toc ';
command_args.push('-x');
command_args.push('toc');
}
if ( this.table ) {
command += '-x table ';
}

command += this.tempFile + ' ';

command += '> ' + this.output;

// Execute the command
cp.exec( command, function( err, stdout, stderr ) {
command_args.push('-x');
command_args.push('table');
}

command_args.push(this.tempFile);
var outputStream = fs.createWriteStream(this.output);
var writeError = null;
outputStream.on('error', function(err) {
writeError = err;
});

var markdown_py = cp.execFile(command, command_args, function( err, stdout, stderr ) {
if ( err ) throw err;

// Append the header


outputStream.write(stdout);
if ( writeError )
{
console.log(`'\nFailed to write to \u001b[32m${that.output}\u001b[0m\n'`);
fs.unlinkSync( that.tempFile );
return;
}
// Now append a little string to the generated file
fs.appendFileSync( that.output, getFoot.bind( that )() );
outputStream.write(getFoot.bind( that )() );

// Delete the temporary file
fs.unlinkSync( that.tempFile );

console.log( '\nDocumentation generated at \u001b[32m' + that.output + '\u001b[0m\n' );
});
})
}
};

Expand Down