Cscott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/96501


Change subject: Improve documentation comments.
......................................................................

Improve documentation comments.

Change-Id: I767232f1b5b8d5edbb23b8a81f1d7995c84c8b65
---
M lib/index.js
1 file changed, 34 insertions(+), 7 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
 refs/changes/01/96501/1

diff --git a/lib/index.js b/lib/index.js
index c20a009..04e5a51 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -33,6 +33,8 @@
        "\\definecolor{linkcolor}{rgb}{.27,0,0}",
        "\\definecolor{citecolor}{rgb}{0,0,.27}",
        
"\\usepackage[colorlinks,breaklinks,allcolors=linkcolor,linkcolor=citecolor]{hyperref}",
+       // Set up Gentium latin fonts
+       // XXX add non-latin (CJK, etc) fonts
        "\\setmainfont[",
        //"Ligatures = {Common,TeX},",
        "Path = " + path.join(__dirname, "..", "fonts") + "/ ,",
@@ -46,8 +48,10 @@
 var STD_FOOTER = [
 ].join("\n");
 
+// Convert plain text (with HTML whitespace semantics) to an appropriately
+// escaped string for TeX to process.
 var texEscape = function(str) {
-       // protect special characters
+       // protect TeX special characters
        str = str.replace(/[#$&~_^%{}\\]/g, function(c) { return '\\' + c; });
        // compress multiple newlines (and use unix-style newlines exclusively)
        str = str.replace(/\r\n?/g, '\n').replace(/\n\n+/g, '\n');
@@ -56,6 +60,7 @@
        // non-breaking space
        str = str.replace(/\xA0/g, '~');
        // smart quotes
+       // XXX smart quotes should probably be disabled in some locales
        str = str.replace(/(^|\s|\()["](\w)/g, function(match, before, after) {
                return before + '\u201C' + after;
        }).replace(/(\w|[.,])["](\s|[.,\u2014\)]|$)/g, function(match, before, 
after) {
@@ -66,6 +71,8 @@
        return str;
 };
 
+// Special predicate for some image templates used on enwiki
+// XXX restrict to enwiki content?
 var isMultipleImageTemplate = function(node) {
        if (node.getAttribute('typeof') === 'mw:Transclusion') {
                try {
@@ -80,6 +87,7 @@
        return false;
 };
 
+// Predicate to distinguish 'nonprintable' content.
 var isHidden = function(node) {
        if (isMultipleImageTemplate(node)) {
                return false;
@@ -91,7 +99,8 @@
                (node.getAttribute('style') || '')) {
                return true;
        }
-       // bit of a hack: hide infobox / navbox / rellink / dablink
+       // bit of a hack: hide infobox / navbox / rellink / dablink / metadata
+       // XXX restrict to enwiki or localize?
        if (['infobox', 'navbox', 'rellink', 'dablink', 
'metadata'].some(function(c) {
                return node.classList.contains(c);
        })) {
@@ -100,6 +109,8 @@
        return false;
 };
 
+/* Document node visitor class.  Collects LaTeX output as it traverses the
+ * document tree. */
 var Visitor = function(document, options) {
        this.document = document;
        this.options = options;
@@ -108,6 +119,9 @@
        this.base = options.base || '';
 };
 
+// Helper function -- collect all text from the children of `node` as
+// HTML non-block/TeX non-paragraph content.  Invoke `f` with the result,
+// suitable for inclusion in a TeX non-paragraph context.
 Visitor.prototype.collect = function(node, f) {
        var o = this.output;
        this.output = [];
@@ -123,6 +137,8 @@
        return f.call(this, text);
 };
 
+// Generic node visitor.  Dispatches to specialized visitors based on
+// element typeof/rel attributes or tag name.
 Visitor.prototype.visit = function(node) {
        var name = node.nodeName, type = node.nodeType;
        switch(type) {
@@ -169,6 +185,7 @@
        }
 };
 
+// Generic helper to recurse into the children of the given node.
 Visitor.prototype.visitChildren = function(node) {
        for (var i = 0, n = node.childNodes.length; i < n; i++) {
                this.visit(node.childNodes[i]);
@@ -435,8 +452,11 @@
        return this.visitChildren(node);
 };
 
-// return a promise for the latex output (after the bundle has been
-// unpacked and processed)
+// ---------------------------------------------------------------------
+// Bundle, image, and file processing
+
+// return a promise for the builddir and control file contents
+// (after the bundle has been unpacked)
 var unpackBundle = function(options) {
        var metabook, builddir;
        // first create a temporary directory
@@ -474,6 +494,8 @@
        });
 };
 
+// return a promise for a map from file resource URLs to on-disk filenames
+// (after image processing / renaming has been done)
 var processImages = function(metabook, builddir, options) {
        options.log('Processing images');
        var imagemap = new Map();
@@ -498,6 +520,7 @@
        });
 };
 
+// Return an empty promise after the output.tex file has been written.
 var generateLatex = function(metabook, builddir, imagemap, options) {
        var output = fs.createWriteStream(path.join(builddir, 'output.tex'), {
                encoding: 'utf8'
@@ -539,6 +562,8 @@
        return p;
 };
 
+// Return an empty promise after the latex has been either written or
+// compiled to a PDF.
 var compileLatex = function(builddir, options) {
        options.log('Compiling to PDF with xelatex');
        gammalatex.setCompileCommand({
@@ -553,13 +578,13 @@
        gammalatex.addRerunIndicator("Package hyperref Warning: Rerun");
        var latexOutput = '\\input{' + path.join(builddir, 'output.tex') + 
'}\n';
 
-       var deferred = when.defer();
+       var deferred = when.defer(); // this will resolve when writeStream is 
closed
        var writeStream;
        if (options.output) {
                writeStream = fs.createWriteStream(options.output);
        } else {
                // trivially wrap process.stdout so we don't get an error when
-               // pipe() tries to close it (stdout can't be closed)
+               // pipe() tries to close it (stdout can't be closed w/o 
throwing)
                writeStream = new stream.Writable();
                writeStream._write = function(chunk, encoding, callback) {
                        return process.stdout.write(chunk, encoding, callback);
@@ -581,6 +606,8 @@
        return deferred.promise;
 };
 
+// Return a promise for an exit status (0 for success) after the bundle
+// specified in the options has been converted.
 var convert = function(options) {
        var metabook, builddir, imagemap;
        return when.resolve().then(function() {
@@ -614,6 +641,6 @@
 };
 
 module.exports = {
-       version: json.version,
+       version: json.version, // version # for this code
        convert: convert
 };

-- 
To view, visit https://gerrit.wikimedia.org/r/96501
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I767232f1b5b8d5edbb23b8a81f1d7995c84c8b65
Gerrit-PatchSet: 1
Gerrit-Project: 
mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to