mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Adds Pretty Printed Source Code To Docs
Plugin generates pages using google prettify to highlight the source. The three css files are the defaults that come with google prettify. The plugin is set up to use the desert style as it's default stylesheet, with prettify, sunburst and prettify-jsdoc listed as alternative stylesheets. Currently this plugin is not tied in with any template. There won't be links in the documentation to bring you to the prettified source.
This commit is contained in:
parent
8bc3354154
commit
77e2bd5f7a
110
plugins/prettyPrintSource.js
Normal file
110
plugins/prettyPrintSource.js
Normal file
@ -0,0 +1,110 @@
|
||||
/**
|
||||
* @file Adds pretty printed source code to
|
||||
* the output files.
|
||||
* @author <a href="mailto:matthewkastor@google.com">Matthew Christopher Kastor-Inare III</a>
|
||||
* 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 = '<!DOCTYPE html>\n';
|
||||
outsource += ' <head>\n';
|
||||
outsource += ' <meta charset="utf-8">\n';
|
||||
outsource += ' <title>Source of : ' + outfile + '</title>\n';
|
||||
outsource += ' <script src="scripts/prettify/prettify.js"> </script>\n';
|
||||
outsource += ' <!--[if lt IE 9]>\n';
|
||||
outsource += ' <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>\n';
|
||||
outsource += ' <![endif]-->\n';
|
||||
outsource += ' <link type="text/css" title="desert" rel="stylesheet" href="styles/desert.css">\n';
|
||||
outsource += ' <link type="text/css" title="sunburst" rel="alternate stylesheet" href="styles/sunburst.css">\n';
|
||||
outsource += ' <link type="text/css" title="prettify" rel="alternate stylesheet" href="styles/prettify.css">\n';
|
||||
outsource += ' <link type="text/css" title="prettify-jsdoc" rel="alternate stylesheet" href="styles/prettify-jsdoc.css">\n';
|
||||
outsource += ' </head>\n';
|
||||
outsource += ' <body>\n';
|
||||
outsource += ' <pre class="prettyprint lang-js linenums">\n';
|
||||
outsource += sourceContent;
|
||||
outsource += ' </pre>\n';
|
||||
outsource += ' <script>prettyPrint();</script>';
|
||||
outsource += ' </body>'
|
||||
outsource += '</html>\n';
|
||||
|
||||
fs.mkPath(outDir);
|
||||
fs.writeFileSync(outfile, outsource);
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
var sourceFileName= bs2fs(e.filename);
|
||||
var sourceContent = e.source;
|
||||
var outFileName = makeOutputFileName(sourceFileName, '.html');
|
||||
var outDir = getOutputDirectory();
|
||||
var outfile = outDir + outFileName;
|
||||
|
||||
// Debug
|
||||
/*
|
||||
dump(fs);
|
||||
print('source file name = ' + sourceFileName);
|
||||
print('output file name = ' + outFileName);
|
||||
print('output directory = ' + outDir);
|
||||
print('output file = ' + outfile);
|
||||
print('sourceContent = ' + sourceContent);
|
||||
//*/
|
||||
|
||||
// write source to file with a unique name
|
||||
generateHighlightedSourceFile(outDir, outfile, sourceContent);
|
||||
// link to source in documentation somehow
|
||||
}
|
||||
|
||||
main();
|
||||
}
|
||||
};
|
||||
34
templates/default/static/styles/desert.css
Normal file
34
templates/default/static/styles/desert.css
Normal file
@ -0,0 +1,34 @@
|
||||
/* desert scheme ported from vim to google prettify */
|
||||
pre { display: block; background-color: #333 }
|
||||
pre .nocode { background-color: none; color: #000 }
|
||||
pre .str { color: #ffa0a0 } /* string - pink */
|
||||
pre .kwd { color: #f0e68c; font-weight: bold }
|
||||
pre .com { color: #87ceeb } /* comment - skyblue */
|
||||
pre .typ { color: #98fb98 } /* type - lightgreen */
|
||||
pre .lit { color: #cd5c5c } /* literal - darkred */
|
||||
pre .pun { color: #fff } /* punctuation */
|
||||
pre .pln { color: #fff } /* plaintext */
|
||||
pre .tag { color: #f0e68c; font-weight: bold } /* html/xml tag - lightyellow */
|
||||
pre .atn { color: #bdb76b; font-weight: bold } /* attribute name - khaki */
|
||||
pre .atv { color: #ffa0a0 } /* attribute value - pink */
|
||||
pre .dec { color: #98fb98 } /* decimal - lightgreen */
|
||||
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums { margin-top: 0; margin-bottom: 0; color: #AEAEAE } /* IE indents via margin-left */
|
||||
li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8 { list-style-type: none }
|
||||
/* Alternate shading for lines */
|
||||
li.L1,li.L3,li.L5,li.L7,li.L9 { }
|
||||
|
||||
@media print {
|
||||
pre { background-color: none }
|
||||
pre .str, code .str { color: #060 }
|
||||
pre .kwd, code .kwd { color: #006; font-weight: bold }
|
||||
pre .com, code .com { color: #600; font-style: italic }
|
||||
pre .typ, code .typ { color: #404; font-weight: bold }
|
||||
pre .lit, code .lit { color: #044 }
|
||||
pre .pun, code .pun { color: #440 }
|
||||
pre .pln, code .pln { color: #000 }
|
||||
pre .tag, code .tag { color: #006; font-weight: bold }
|
||||
pre .atn, code .atn { color: #404 }
|
||||
pre .atv, code .atv { color: #060 }
|
||||
}
|
||||
52
templates/default/static/styles/prettify.css
Normal file
52
templates/default/static/styles/prettify.css
Normal file
@ -0,0 +1,52 @@
|
||||
/* Pretty printing styles. Used with prettify.js. */
|
||||
|
||||
/* SPAN elements with the classes below are added by prettyprint. */
|
||||
.pln { color: #000 } /* plain text */
|
||||
|
||||
@media screen {
|
||||
.str { color: #080 } /* string content */
|
||||
.kwd { color: #008 } /* a keyword */
|
||||
.com { color: #800 } /* a comment */
|
||||
.typ { color: #606 } /* a type name */
|
||||
.lit { color: #066 } /* a literal value */
|
||||
/* punctuation, lisp open bracket, lisp close bracket */
|
||||
.pun, .opn, .clo { color: #660 }
|
||||
.tag { color: #008 } /* a markup tag name */
|
||||
.atn { color: #606 } /* a markup attribute name */
|
||||
.atv { color: #080 } /* a markup attribute value */
|
||||
.dec, .var { color: #606 } /* a declaration; a variable name */
|
||||
.fun { color: red } /* a function name */
|
||||
}
|
||||
|
||||
/* Use higher contrast and text-weight for printable form. */
|
||||
@media print, projection {
|
||||
.str { color: #060 }
|
||||
.kwd { color: #006; font-weight: bold }
|
||||
.com { color: #600; font-style: italic }
|
||||
.typ { color: #404; font-weight: bold }
|
||||
.lit { color: #044 }
|
||||
.pun, .opn, .clo { color: #440 }
|
||||
.tag { color: #006; font-weight: bold }
|
||||
.atn { color: #404 }
|
||||
.atv { color: #060 }
|
||||
}
|
||||
|
||||
/* Put a border around prettyprinted code snippets. */
|
||||
pre.prettyprint { padding: 2px; border: 1px solid #888 }
|
||||
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums { margin-top: 0; margin-bottom: 0 } /* IE indents via margin-left */
|
||||
li.L0,
|
||||
li.L1,
|
||||
li.L2,
|
||||
li.L3,
|
||||
li.L5,
|
||||
li.L6,
|
||||
li.L7,
|
||||
li.L8 { list-style-type: none }
|
||||
/* Alternate shading for lines */
|
||||
li.L1,
|
||||
li.L3,
|
||||
li.L5,
|
||||
li.L7,
|
||||
li.L9 { background: #eee }
|
||||
51
templates/default/static/styles/sunburst.css
Normal file
51
templates/default/static/styles/sunburst.css
Normal file
@ -0,0 +1,51 @@
|
||||
/* Pretty printing styles. Used with prettify.js. */
|
||||
/* Vim sunburst theme by David Leibovic */
|
||||
|
||||
pre .str, code .str { color: #65B042; } /* string - green */
|
||||
pre .kwd, code .kwd { color: #E28964; } /* keyword - dark pink */
|
||||
pre .com, code .com { color: #AEAEAE; font-style: italic; } /* comment - gray */
|
||||
pre .typ, code .typ { color: #89bdff; } /* type - light blue */
|
||||
pre .lit, code .lit { color: #3387CC; } /* literal - blue */
|
||||
pre .pun, code .pun { color: #fff; } /* punctuation - white */
|
||||
pre .pln, code .pln { color: #fff; } /* plaintext - white */
|
||||
pre .tag, code .tag { color: #89bdff; } /* html/xml tag - light blue */
|
||||
pre .atn, code .atn { color: #bdb76b; } /* html/xml attribute name - khaki */
|
||||
pre .atv, code .atv { color: #65B042; } /* html/xml attribute value - green */
|
||||
pre .dec, code .dec { color: #3387CC; } /* decimal - blue */
|
||||
|
||||
pre.prettyprint, code.prettyprint {
|
||||
background-color: #000;
|
||||
-moz-border-radius: 8px;
|
||||
-webkit-border-radius: 8px;
|
||||
-o-border-radius: 8px;
|
||||
-ms-border-radius: 8px;
|
||||
-khtml-border-radius: 8px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
pre.prettyprint {
|
||||
width: 95%;
|
||||
margin: 1em auto;
|
||||
padding: 1em;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums { margin-top: 0; margin-bottom: 0; color: #AEAEAE; } /* IE indents via margin-left */
|
||||
li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8 { list-style-type: none }
|
||||
/* Alternate shading for lines */
|
||||
li.L1,li.L3,li.L5,li.L7,li.L9 { }
|
||||
|
||||
@media print {
|
||||
pre .str, code .str { color: #060; }
|
||||
pre .kwd, code .kwd { color: #006; font-weight: bold; }
|
||||
pre .com, code .com { color: #600; font-style: italic; }
|
||||
pre .typ, code .typ { color: #404; font-weight: bold; }
|
||||
pre .lit, code .lit { color: #044; }
|
||||
pre .pun, code .pun { color: #440; }
|
||||
pre .pln, code .pln { color: #000; }
|
||||
pre .tag, code .tag { color: #006; font-weight: bold; }
|
||||
pre .atn, code .atn { color: #404; }
|
||||
pre .atv, code .atv { color: #060; }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user