diff --git a/plugins/prettyPrintSource.js b/plugins/prettyPrintSource.js new file mode 100644 index 000000000..a2113b967 --- /dev/null +++ b/plugins/prettyPrintSource.js @@ -0,0 +1,114 @@ +/** + * @file Adds pretty printed source code to + * the output files. + * @author Matthew Christopher Kastor-Inare III + * Hial Atropa!! + * @version 20121017 + */ + +exports.handlers = { + beforeParse: function(e) { + + function bs2fs(text) { + return text.replace(/\\/g, '/'); + } + + function toRelativePath(text) { + return text.replace(/^.*:/, ''); + } + + function slashesCollapseToDots(text) { + return text.replace(/[\/\\]+/g, '.'); + } + + function suffixFsCollapse(text) { + return text.replace(/\/+$/, '/'); + } + + function noDotPrefix(text) { + return text.replace(/^\./, ''); + } + + function makeOutputFileName(sourceFileName, extension) { + extension = extension || ''; + + var out; + + out = toRelativePath(sourceFileName); + out = slashesCollapseToDots(out); + out = noDotPrefix(out) + out += extension; + + return out; + } + + function getOutputDirectory() { + var path = require('path'); + var out; + + out = path.resolve(env.opts.destination); + out = bs2fs(out); + out = suffixFsCollapse(out + '/'); + + return out; + } + + function generateHighlightedSourceFile(outDir, outfile, sourceContent) { + var fs = require('fs'); + var outsource; + + outsource = '\n'; + outsource += '
\n'; + outsource += ' \n'; + outsource += '\n'; + outsource += sourceContent; + outsource += '\n'; + outsource += ' \n'; + outsource += ' \n' + outsource += '