var debug = require('debug')('prerender-mathjax:example') // koa koa = require('koa'), send = require('koa-send'), // prerender-mathjax prerenderMath = require('./lib/prerender-mathjax'), stripmj = require('./lib/strip-mathjax-scripts'); var prerenderMathjax = require('./lib/prerender-mathjax'); module.exports = server; function server(rootpath, options) { var prerender = prerenderMathjax(options); var app = koa(); app.use(function* (next) { debug('serve', this.path); // Using koa-send to put the requested file onto this.body // // This is just for this example. prerender-mathjax simply expects // this.body to be a String, Buffer, or Stream. // yield send(this, this.path, { root: rootpath }); // The main event: if `prerender` is a query parameter, then prerender // the math using selected given renderer. match = /prerender=(MML|SVG)/.exec(this.querystring); if(match !== null) yield prerender(this, {renderer: match[1]}); // Just a little helper function to strip out any MathJax-related