Physikerwelt has uploaded a new change for review. https://gerrit.wikimedia.org/r/113913
Change subject: Add makefile ...................................................................... Add makefile Change-Id: Id92aab295d19f5ee0026d03f5e0d4c1d44da1e8e npm version of debian package Change-Id: I5f30ebebae567232778127a95bd3b3306c907af5 Prepere for next build * update changelog * add npm build dependency Change-Id: Ifc558fea814cacb33cd7d6a1d451c04d19009d9f Remove version from the npm dependency for now To buld you need at least npm 1.3.0 but dpgk can not finde the npm version, if npm is installed from ppa:chris-lea/node.js Change-Id: I21d32731f06187ebfaf450164089a597fe63d163 WIP: support for MathML input Mathoid on its way to understand MathML input Change-Id: Ia11de03f7d91ddcca45637c2fd268a0d5a60f405 --- M Makefile M Math A debian/README A debian/README.Debian A debian/README.source A debian/changelog A debian/compat A debian/control A debian/copyright A debian/docs A debian/files A debian/mathoid.debhelper.log A debian/mathoid.default A debian/mathoid.init A debian/mathoid.install A debian/mathoid.logrotate A debian/mathoid.postinst A debian/mathoid.postinst.debhelper A debian/mathoid.postrm A debian/mathoid.preinst.debhelper A debian/mathoid.prerm.debhelper A debian/mathoid.substvars A debian/mathoid.upstart A debian/rules A debian/source/format A debian/upstart/mathoid.conf M engine.js M index.html M main.js M mathoid-worker.js 30 files changed, 585 insertions(+), 34 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mathoid refs/changes/13/113913/1 diff --git a/Makefile b/Makefile index a571329..8b138e0 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,6 @@ -.PHONY: all clean install - -all: install - -install: - npm install - -clean: - rm -rf node_modules +all: + npm install + +.PHONY: clean +clean: + rm -rf node_modules diff --git a/Math b/Math index 7059fc8..d463f88 160000 --- a/Math +++ b/Math -Subproject commit 7059fc825f456ca923f78931341c454211e04623 +Subproject commit d463f88c18b16d06d0af30619d6baf2ded489bc1 diff --git a/debian/README b/debian/README new file mode 100644 index 0000000..6cd09c3 --- /dev/null +++ b/debian/README @@ -0,0 +1,6 @@ +The Debian Package mathoid +---------------------------- + +Comments regarding the Package + + -- Moritz Schubotz (Physikerwelt) <w...@physikerwelt.de> Tue, 11 Feb 2014 17:56:54 +0000 diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..588f126 --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,6 @@ +mathoid for Debian +------------------ + +<possible notes regarding this package - if none, delete this file> + + -- Moritz Schubotz (Physikerwelt) <w...@physikerwelt.de> Tue, 11 Feb 2014 17:56:54 +0000 diff --git a/debian/README.source b/debian/README.source new file mode 100644 index 0000000..11c79ca --- /dev/null +++ b/debian/README.source @@ -0,0 +1,9 @@ +mathoid for Debian +------------------ + +<this file describes information about the source package, see Debian policy +manual section 4.14. You WILL either need to modify or delete this file> + + + + diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..bc8fe16 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,17 @@ +mathoid (0.1.2) precise; urgency=low + + * Change to semantic version numbers + + -- Moritz Schubotz (Physikerwelt) <w...@physikerwelt.de> Wed, 12 Feb 2014 23:46:11 +0000 + +mathoid (0.1-0ubuntu1) precise; urgency=low + + * use npm to build the node_packages folder + + -- Moritz Schubotz (Physikerwelt) <w...@physikerwelt.de> Wed, 12 Feb 2014 21:57:50 +0000 + +mathoid (0.1-0) precise; urgency=low + + * Initial Release. + + -- Moritz Schubotz (Physikerwelt) <w...@physikerwelt.de> Tue, 11 Feb 2014 17:56:54 +0000 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..92d71ee --- /dev/null +++ b/debian/control @@ -0,0 +1,18 @@ +Source: mathoid +Section: web +Priority: extra +Maintainer: Moritz Schubotz (Physikerwelt) <w...@physikerwelt.de> +# To buld you need at least npm 1.3.0 but dpgk can not finde the npm version, +# if npm is installed from ppa:chris-lea/node.js +Build-Depends: debhelper (>= 8.0.0), make, npm (>= 1.3.0) +Standards-Version: 3.9.2 +Homepage: http://www.formulasearchengine.com/Mathoid +Vcs-Git: https://github.com/physikerwelt/mathoid-deploy.git +Vcs-Browser: https://github.com/physikerwelt/mathoid-deploy + +Package: mathoid +Architecture: any +Depends: nodejs (>=0.8.0), phantomjs (>=1.9.0), logrotate, adduser, ${shlibs:Depends}, ${misc:Depends} +Enhances: mediawiki +Description: Web service converting LaTeX to MathML + Conversion from LaTeX to MathML node.js web service that uses Phantomjs in the background. See http://www.formulasearchengine.com/mathoid. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..6ba5044 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,30 @@ +Format: http://dep.debian.net/deps/dep5 +Upstream-Name: mathoid +Source: <https://www.formulasearchengine.com/mathoid> +Files: * +Copyright: 2013- The Mathoid authors, see src/COPYING.> +License: GPL-3.0+ + +Files: debian/* +Copyright: 2014 Moritz Schubotz (Physikerwelt) <w...@physikerwelt.de> +License: GPL-3.0+ + +License: GPL-3.0+ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + . + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + . + On Debian systems, the complete text of the GNU General + Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/debian/docs diff --git a/debian/files b/debian/files new file mode 100644 index 0000000..68e57b1 --- /dev/null +++ b/debian/files @@ -0,0 +1 @@ +mathoid_0.1-0ubuntu1_amd64.deb web extra diff --git a/debian/mathoid.debhelper.log b/debian/mathoid.debhelper.log new file mode 100644 index 0000000..0924d1f --- /dev/null +++ b/debian/mathoid.debhelper.log @@ -0,0 +1,47 @@ +dh_auto_configure +dh_auto_build +dh_auto_test +dh_prep +dh_installdirs +dh_auto_install +dh_install +dh_installdocs +dh_installchangelogs +dh_installexamples +dh_installman +dh_installcatalogs +dh_installcron +dh_installdebconf +dh_installemacsen +dh_installifupdown +dh_installinfo +dh_installinit +dh_installmenu +dh_installmime +dh_installmodules +dh_installlogcheck +dh_installlogrotate +dh_installpam +dh_installppp +dh_installudev +dh_installwm +dh_installxfonts +dh_installgsettings +dh_bugfiles +dh_ucf +dh_lintian +dh_gconf +dh_icons +dh_perl +dh_usrlocal +dh_link +dh_compress +dh_fixperms +dh_strip +dh_makeshlibs +dh_shlibdeps +dh_installdeb +dh_gencontrol +dh_md5sums +dh_builddeb +dh_builddeb diff --git a/debian/mathoid.default b/debian/mathoid.default new file mode 100644 index 0000000..4d3b262 --- /dev/null +++ b/debian/mathoid.default @@ -0,0 +1,10 @@ +# Defaults for mathoid initscript + +# File where the mathoid daemon will write stderr and stdout to +MATHOID_LOG_FILE=/var/log/mathoid/mathoid.log + +MATHOID_PORT="10042" + +# Default is to listen on all interfaces +#MATHOID_INTERFACE="0.0.0.0" + diff --git a/debian/mathoid.init b/debian/mathoid.init new file mode 100644 index 0000000..0ecec3e --- /dev/null +++ b/debian/mathoid.init @@ -0,0 +1,164 @@ +#!/bin/sh +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="Mathoid HTTP service" +NAME=mathoid +SCRIPT_PATH=/usr/lib/mathoid/src/mathoid.js +DAEMON="/usr/bin/nodejs $SCRIPT_PATH" +#DAEMON_ARGS="" +PIDFILE=/var/run/$NAME.pid +#SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -e "$SCRIPT_PATH" ] || exit 0 + +# Read configuration variable file if it is present +#[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# export the port and host env vars, if set +if [ ! -z "$MATHOID_PORT" ];then + export MATHOID_PORT="$MATHOID_PORT" +fi +#if [ ! -z "$MATHOID_INTERFACE" ];then +# export MATHOID_INTERFACE="$MATHOID_INTERFACE" +#fi + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.2-14) to ensure that this file is present +# and status_of_proc is working. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --pidfile $PIDFILE -bm --no-close \ + -c mathoid:mathoid \ + --exec $DAEMON --test > /dev/null \ + || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE -bm --no-close \ + -c mathoid:mathoid \ + --exec $DAEMON -- $DAEMON_ARGS >> /var/log/mathoid/mathoid.log 2>&1 \ + || return 2 + # The above code will not work for interpreted scripts, use the next + # six lines below instead (Ref: #643337, start-stop-daemon(8) ) + #start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \ + # --name $NAME --test > /dev/null \ + # || return 1 + #start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \ + # --name $NAME -- $DAEMON_ARGS \ + # || return 2 + + # Add code here, if necessary, that waits for the process to be ready + # to handle requests from services started subsequently which depend + # on this one. As a last resort, sleep for some time. + sleep 5 +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/5/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + # Wait for children to finish too if this is a daemon that forks + # and if the daemon is only ever run from this initscript. + # If the above conditions are not satisfied then add some other code + # that waits for the process to drop all resources that could be + # needed by services started subsequently. A last resort is to + # sleep for some time. + start-stop-daemon --stop --quiet --oknodo --retry=0/5/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + # + # If the daemon can reload its configuration without + # restarting (for example, when it is sent a SIGHUP), + # then implement that here. + # + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + return 0 +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + #reload|force-reload) + # + # If do_reload() is not implemented then leave this commented out + # and leave 'force-reload' as an alias for 'restart'. + # + #log_daemon_msg "Reloading $DESC" "$NAME" + #do_reload + #log_end_msg $? + #;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/debian/mathoid.install b/debian/mathoid.install new file mode 100644 index 0000000..191b5d2 --- /dev/null +++ b/debian/mathoid.install @@ -0,0 +1,14 @@ +# main source +engine.js usr/lib/mathoid/ +index.html usr/lib/mathoid/ +LICENSE.txt usr/lib/mathoid/ +mathoid.config.json usr/lib/mathoid/ +mathoid.js usr/lib/mathoid/ +mathoid-worker.js usr/lib/mathoid/ +README.md usr/lib/mathoid/ +main.js usr/lib/mathoid/ +# node modules +node_modules/ usr/lib/mathoid/ +package.json usr/lib/mathoid/ +#MathJax +Math/ usr/lib/mathoid/ \ No newline at end of file diff --git a/debian/mathoid.logrotate b/debian/mathoid.logrotate new file mode 100644 index 0000000..d08847b --- /dev/null +++ b/debian/mathoid.logrotate @@ -0,0 +1,9 @@ +/var/log/mathoid/mathoid.log { + daily + copytruncate + missingok + compress + notifempty + rotate 15 + size 256M +} diff --git a/debian/mathoid.postinst b/debian/mathoid.postinst new file mode 100644 index 0000000..cbcf82d --- /dev/null +++ b/debian/mathoid.postinst @@ -0,0 +1,56 @@ +#!/bin/sh +# postinst script for mathoid +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * <postinst> `configure' <most-recently-configured-version> +# * <old-postinst> `abort-upgrade' <new version> +# * <conflictor's-postinst> `abort-remove' `in-favour' <package> +# <new-version> +# * <postinst> `abort-remove' +# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' +# <failed-install-package> <version> `removing' +# <conflicting-package> <version> +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +makedir() { + if [ ! -d $1 ]; then + mkdir $1 + fi + chown $2 $1 && chmod $3 $1 +} + +# make sure that the mathoid user exists. Simplest portable way to check is to +# chown something, so we'll create the directories that we need here. +cd /var/log +makedir mathoid root:root 700 +chgrp mathoid mathoid 2>/dev/null || + addgroup --system mathoid +chown mathoid mathoid 2>/dev/null || + adduser --system --home /usr/lib/mathoid --no-create-home \ + --disabled-password --ingroup mathoid mathoid +makedir mathoid mathoid:mathoid 700 +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/mathoid.postinst.debhelper b/debian/mathoid.postinst.debhelper new file mode 100644 index 0000000..8da8077 --- /dev/null +++ b/debian/mathoid.postinst.debhelper @@ -0,0 +1,8 @@ +# Automatically added by dh_installinit +if [ -e "/etc/init/mathoid.conf" ]; then + invoke-rc.d mathoid start || exit $? +fi +# End automatically added section +# Automatically added by dh_installinit +update-rc.d -f mathoid remove >/dev/null || exit $? +# End automatically added section diff --git a/debian/mathoid.postrm b/debian/mathoid.postrm new file mode 100644 index 0000000..bc23f40 --- /dev/null +++ b/debian/mathoid.postrm @@ -0,0 +1,59 @@ +#!/bin/sh +# postrm script for mathoid +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * <postrm> `remove' +# * <postrm> `purge' +# * <old-postrm> `upgrade' <new-version> +# * <new-postrm> `failed-upgrade' <old-version> +# * <new-postrm> `abort-install' +# * <new-postrm> `abort-install' <old-version> +# * <new-postrm> `abort-upgrade' <old-version> +# * <disappearer's-postrm> `disappear' <overwriter> +# <overwriter-version> +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + + +if [ "$1" = "purge" ] ; then + # Delete user; recipe from + # https://wiki.debian.org/AccountHandlingInMaintainerScripts + USERNAME=mathoid + if [ -x "$(command -v deluser)" ]; then + deluser --quiet --system $USERNAME > /dev/null || true + else + echo >&2 "not removing $USERNAME system account because deluser command was not found" + fi + + # Delete directory for pid file + if [ -d "/var/run/mathoid" ]; then + rm -rf "/var/run/mathoid" + fi + + # Delete directory for log files + if [ -d "/var/log/mathoid" ]; then + rm -rf "/var/log/mathoid" + fi +fi + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/mathoid.preinst.debhelper b/debian/mathoid.preinst.debhelper new file mode 100644 index 0000000..599ebf2 --- /dev/null +++ b/debian/mathoid.preinst.debhelper @@ -0,0 +1,14 @@ +# Automatically added by dh_installinit +if [ "$1" = install ] || [ "$1" = upgrade ]; then + if [ -e "/etc/init.d/mathoid" ] && [ ! -L "/etc/init.d/mathoid" ]; then + if [ "`md5sum \"/etc/init.d/mathoid\" | sed -e \"s/ .*//\"`" != \ + "`dpkg-query -W -f='${Conffiles}' mathoid | sed -n -e \"\\\\' /etc/init.d/mathoid '{s/ obsolete$//;s/.* //p}\"`" ] + then + echo "Obsolete conffile /etc/init.d/mathoid has been modified by you, renaming to .dpkg-bak" + mv -f "/etc/init.d/mathoid" "/etc/init.d/mathoid.dpkg-bak" + else + rm -f "/etc/init.d/mathoid" + fi + fi +fi +# End automatically added section diff --git a/debian/mathoid.prerm.debhelper b/debian/mathoid.prerm.debhelper new file mode 100644 index 0000000..e18e56c --- /dev/null +++ b/debian/mathoid.prerm.debhelper @@ -0,0 +1,5 @@ +# Automatically added by dh_installinit +if [ -e "/etc/init/mathoid.conf" ]; then + invoke-rc.d mathoid stop || exit $? +fi +# End automatically added section diff --git a/debian/mathoid.substvars b/debian/mathoid.substvars new file mode 100644 index 0000000..4a97bd3 --- /dev/null +++ b/debian/mathoid.substvars @@ -0,0 +1,2 @@ +misc:Depends=upstart-job +perl:Depends=perl diff --git a/debian/mathoid.upstart b/debian/mathoid.upstart new file mode 100644 index 0000000..6f3c6a6 --- /dev/null +++ b/debian/mathoid.upstart @@ -0,0 +1,31 @@ +# vim: set ft=upstart: + +description "Mathoid HTTP service" + +start on (local-filesystem and net-device-up IFACE!=lo) +stop on runlevel [!2345] + +# up ulimit -n a bit +limit nofile 10000 10000 + +setuid "mathoid" +setgid "mathoid" + +env DEFAULTFILE=/etc/default/mathoid + +# Basic built-in defaults. Overridden by whatever +# is defined in the DEFAULTFILE defined above. +env NODE_PATH="/usr/lib/mathoid/node_modules" +env MATHOID_BASE_PATH="/usr/lib/mathoid" +env MATHOID_LOG_FILE="/var/log/mathoid/mathoid.log" +env MATHOID_PORT="8010" + +respawn + +script + if [ -f "$DEFAULTFILE" ] ; then + . "$DEFAULTFILE" + fi + chdir "$MATHOID_BASE_PATH" + exec /usr/bin/nodejs mathoid.js < /dev/null >> "$MATHOID_LOG_FILE" 2>&1 +end script diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..0869290 --- /dev/null +++ b/debian/rules @@ -0,0 +1,13 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/debian/upstart/mathoid.conf b/debian/upstart/mathoid.conf new file mode 100644 index 0000000..5431a87 --- /dev/null +++ b/debian/upstart/mathoid.conf @@ -0,0 +1,18 @@ +# vim: set ft=upstart: + +# Upstart job configuration for Mathoid + +description "Mathoid HTTP service" + +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [!2345] + +setuid "mathoid" +setgid "mathoid" + +env VCAP_APP_PORT="8010" + +chdir "/var/lib/mathoid/src" +exec node mathoid.js + +respawn \ No newline at end of file diff --git a/engine.js b/engine.js index 26ee420..65d93c6 100644 --- a/engine.js +++ b/engine.js @@ -28,7 +28,7 @@ // point to our jax. this.init = function() { this.Q.Push(this.bind(function () { - this.math = MathJax.Hub.getAllJax('math')[0]; + this.math = MathJax.Hub.getAllJax('mathInput')[0]; this.processBuffered(); })); }; @@ -36,7 +36,7 @@ // receives input latex string and invokes cb // function with svg result. this.processCB = function(latex, cb) { - this.Q.Push(['Text', this.math, latex]); + this.Q.Push(['Text', this.math, latex[0]]); this.Q.Push(this.bind(function() { // then, this toSVG call will invoke cb(result). cb(document.getElementsByTagName('svg')[1].cloneNode(true)); @@ -113,20 +113,26 @@ // if there is an error during the latex rendering then second // element (instead of SVG output) will be array again with // only one string element describing the error message. - this.process = function(latex, cb) { + this.process = function(input, cb) { + var value = input[0], + type = input[1]; if (this.math === null) { - this.buffer.push( [latex, cb] ); + this.buffer.push( [input, cb] ); } else { try{ - this.processCB(latex, this.bind(function( ) { + this.processCB(input, this.bind(function( ) { var jax = MathJax.Hub.getAllJax(), mergedSVG = this.merge(document.getElementsByTagName('svg')[1].cloneNode(true)); - toMathML(jax[0],function (mml) { - cb([latex, mergedSVG, mml]); - }); + if( input[1] == 'tex'){ + toMathML(jax[0],function (mml) { + cb([input[0], mergedSVG, mml]); + }); + } else { + cb([input[0], mergedSVG, input[0]]); + } })); } catch (err) { - cb([latex, err, err]); + cb([input[0], err, err]); } } }; diff --git a/index.html b/index.html index 94e8837..3e6da17 100644 --- a/index.html +++ b/index.html @@ -5,12 +5,14 @@ <head> <script type="text/javascript"> MathJax = { - jax: ["input/TeX","output/SVG","output/NativeMML"], - extensions: ["tex2jax.js","toMathML.js","TeX/noErrors.js","TeX/noUndefined.js","TeX/AMSmath.js","TeX/AMSsymbols.js"], + jax: ["input/TeX", + "input/MathML","output/SVG","output/NativeMML"], + extensions: ["mml2jax.js", + "tex2jax.js","toMathML.js", "TeX/noErrors.js","TeX/noUndefined.js","TeX/AMSmath.js","TeX/AMSsymbols.js"], showProcessingMessages: false, messageStyle: "none", tex2jax: { - inlineMath: [["$","$"],["\\(","\\)"]] + inlineMath: [["$","$"]] } }; </script> @@ -21,4 +23,4 @@ <body> <div id="math">${}$</div> </body> -</html> + </html> diff --git a/main.js b/main.js index 4d6a4e1..0c69247 100644 --- a/main.js +++ b/main.js @@ -28,7 +28,7 @@ if ((typeof data[1]) === 'string') { resp.statusCode = 200; log = data[0].substr(0, 30) + '.. ' + data[0].length + 'B query, OK ' + data[1].length + '/' + data[2].length + 'B result' + t; - out = JSON.stringify({tex:data[0],svg:data[1],mml:data[2],'log':log, 'sucess':true}); + out = JSON.stringify({input:data[0],svg:data[1],mml:data[2],'log':log, 'sucess':true}); resp.setHeader('Content-Type', 'application/json'); resp.setHeader('Content-Length', utf8Strlen(out).toString() ); resp.write(out); @@ -53,16 +53,22 @@ // URL starts with /? and is urlencoded. query = decodeURI(req.url.substr(2)); } else { - query = req.post.tex; + if( req.post.inputMML ){ + query = [req.post.tex,"MathMl"]; + } else { + query = [req.post.tex, "tex"]; + } } + alert('test'); if (query === undefined) { return resp.close(); } - activeRequests[query] = [resp, (new Date()).getTime()]; - // this is just queueing call, it will return at once. - page.evaluate(function(q) { - window.engine.process(q, window.callPhantom); - }, query); + + activeRequests[query[0]] = [resp, (new Date()).getTime()]; + // this is just queueing call, it will return at once. + page.evaluate(function(q) { + window.engine.process(q, window.callPhantom); + }, query); }); if (!service) { diff --git a/mathoid-worker.js b/mathoid-worker.js index 8852899..0199a20 100644 --- a/mathoid-worker.js +++ b/mathoid-worker.js @@ -93,9 +93,9 @@ -function handleRequest(req, res, tex) { +function handleRequest(req, res, tex, inputMML) { // do the backend request - var reqbody = new Buffer(querystring.stringify({tex: tex})), + var reqbody = new Buffer(querystring.stringify({tex: tex, inputMML: inputMML})), options = { method: 'POST', uri: 'http://localhost:' + backendPort.toString() + '/', @@ -154,13 +154,14 @@ app.post(/^\/$/, function ( req, res ) { // First some rudimentary input validation - if (!req.body.tex) { + if (!(req.body.tex||req.body.mml)) { res.writeHead(400); - return res.end(JSON.stringify({error: "'tex' post parameter is missing!"})); + return res.end(JSON.stringify({error: "'tex' or 'mml' post parameter is missing!"})); } var tex = req.body.tex; + var inputMML = req.body.mml; - requestQueue.push(handleRequest.bind(null, req, res, tex)); + requestQueue.push(handleRequest.bind(null, req, res, tex, inputMML)); // phantomjs only handles one request at a time. Enforce this. if (requestQueue.length === 1) { // Start this process -- To view, visit https://gerrit.wikimedia.org/r/113913 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia11de03f7d91ddcca45637c2fd268a0d5a60f405 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mathoid Gerrit-Branch: master Gerrit-Owner: Physikerwelt <w...@physikerwelt.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits