function client_table(resp, query) {
  log(query.num + ": returning client template");
  var formulas = query.q;
  var width = query.width || null;

  // We have to do some munging of the mathjax_url to avoid the 15-second problem.
  // This is a nasty hack, but I can't think of a better solution. The problem is that
  // PMC mathjax config files must be invoked host-relative, because they have this line
  // at the end:
  //    MathJax.Ajax.loadComplete("/corehtml/pmc/js/mathjax-config-classic.3.4.1.js");
  // But, inside phantomjs, if you try to use host-relative URL for the mathjax config
  // file, it fails. So, we've configured our servers to start phantomjs using the
  // full URLs of the config file, including domain, like this:
  //    phantomjs main.js --mathjax=https://www.ncbi.nlm.nih.gov/core/mathjax/2.5/MathJax.js?\
  //        config=https://www.ncbi.nlm.nih.gov/corehtml/pmc/js/mathjax-config-classic.3.4.1.js
  // But that means that, when setting the script tag in the page returned to the client,
  // we have to strip out the schema and domain from the config file URL.
  var re = /(https?:\/\/([a-z]+)\.ncbi\.nlm\.nih\.gov[^?]*)\?config=https?:\/\/([a-z]+)\.ncbi\.nlm\.nih\.gov(.*)/;
  var m = mathjax_url.match(re);
  if (m && m[2] == m[3]) {
    mathjax_url = m[1] + "?config=" + m[4];
  }




  resp_page = client_template.replace("$mathjax_url", mathjax_url);

  var rows = '';
  formulas.forEach(function(f) {
      rows += make_row(f, width);
  });
  resp_page = resp_page.replace("<!-- rows -->", rows);

  var sources = '';
  formulas.forEach(function(f) {
      sources += make_source(f);
  });
  resp_page = resp_page.replace("<!-- sources -->", sources);


  //var resp_page = client_template.start + rows + client_template.end;
  resp.setHeader('Content-type', 'text/html; charset=utf-8');
  resp.write(resp_page);
  resp.close();
}
// Return an HTML page with a table of equations, for rendering on the client
Return an HTML page with a table of equations, for rendering on the client
Return an HTML page with a table of equations for rendering on the client
function client_table(resp, query) {
  log(query.num + ": returning client template");
  var formulas = query.q;
  var width = query.width || null;
  var re = /(https?:\/\/([a-z]+)\.ncbi\.nlm\.nih\.gov[^?]*)\?config=https?:\/\/([a-z]+)\.ncbi\.nlm\.nih\.gov(.*)/;
  var m = mathjax_url.match(re);
  if (m && m[2] == m[3]) {
    mathjax_url = m[1] + "?config=" + m[4];
  }
  resp_page = client_template.replace("$mathjax_url", mathjax_url);
  var rows = '';
  formulas.forEach(function(f) {
      rows += make_row(f, width);
  });
  resp_page = resp_page.replace("<!-- rows -->", rows);
  var sources = '';
  formulas.forEach(function(f) {
      sources += make_source(f);
  });
  resp_page = resp_page.replace("<!-- sources -->", sources);
  resp.setHeader('Content-type', 'text/html; charset=utf-8');
  resp.write(resp_page);
  resp.close();
}
function client_table ( resp , query ) { log ( query . num + ": returning client template" ) ; var formulas = query . q ; var width = query . width || null ; var re = / (https?:\/\/([a-z]+)\.ncbi\.nlm\.nih\.gov[^?]*)\?config=https?:\/\/([a-z]+)\.ncbi\.nlm\.nih\.gov(.*) / ; var m = mathjax_url . match ( re ) ; if ( m && m [ 2 ] == m [ 3 ] ) { mathjax_url = m [ 1 ] + "?config=" + m [ 4 ] ; } resp_page = client_template . replace ( "$mathjax_url" , mathjax_url ) ; var rows = '' ; formulas . forEach ( function ( f ) { rows += make_row ( f , width ) ; } ) ; resp_page = resp_page . replace ( "<!-- rows -->" , rows ) ; var sources = '' ; formulas . forEach ( function ( f ) { sources += make_source ( f ) ; } ) ; resp_page = resp_page . replace ( "<!-- sources -->" , sources ) ; resp . setHeader ( 'Content-type' , 'text/html; charset=utf-8' ) ; resp . write ( resp_page ) ; resp . close ( ) ; }
Return an HTML page with a table of equations, for rendering on the client
Return an HTML page with a table of equations for rendering on the client
// We have to do some munging of the mathjax_url to avoid the 15-second problem. // This is a nasty hack, but I can't think of a better solution. The problem is that // PMC mathjax config files must be invoked host-relative, because they have this line // at the end: //    MathJax.Ajax.loadComplete("/corehtml/pmc/js/mathjax-config-classic.3.4.1.js"); // But, inside phantomjs, if you try to use host-relative URL for the mathjax config // file, it fails. So, we've configured our servers to start phantomjs using the // full URLs of the config file, including domain, like this: //    phantomjs main.js --mathjax=https://www.ncbi.nlm.nih.gov/core/mathjax/2.5/MathJax.js?\ //        config=https://www.ncbi.nlm.nih.gov/corehtml/pmc/js/mathjax-config-classic.3.4.1.js // But that means that, when setting the script tag in the page returned to the client, // we have to strip out the schema and domain from the config file URL. //var resp_page = client_template.start + rows + client_template.end;