Skip to content

Commit cf01660

Browse files
Added package.json and modified markjax.js
1 parent 2ba1f2e commit cf01660

File tree

5 files changed

+123
-212
lines changed

5 files changed

+123
-212
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2016 CodeAssign
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/markjax');

lib/markjax.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
;(function() {
2+
MathJax.Hub.Config({
3+
showProcessingMessages: false,
4+
tex2jax: {
5+
inlineMath: [['$','$']],
6+
displayMath: [['$$', '$$']],
7+
ignoreClass: ".*",
8+
processClass: "mathjax"
9+
},
10+
TeX: {
11+
equationNumbers: {
12+
autoNumber: "AMS"
13+
}
14+
}
15+
});
16+
17+
marked.setOptions({
18+
renderer: new marked.Renderer(),
19+
gfm: true,
20+
tables: true,
21+
breaks: false,
22+
pedantic: false,
23+
sanitize: false,
24+
smartLists: true,
25+
smartypants: false,
26+
highlight: function (code) {
27+
return hljs.highlightAuto(code).value;
28+
}
29+
});
30+
31+
function EscapeTex(text) {
32+
var re = /(`+)(\s*)([\s\S]*?[^`])(\s*)(\1)(?!`)/g;
33+
var out = text.replace(re, function(m, p1, p2, p3, p4, p5, offset, string) {
34+
return p1 + p2 + p3.replace(/\$/g, '\\$') + p4 + p5;
35+
});
36+
37+
re = /^( {4}[^\n]+\n*)+/g;
38+
out = out.replace(re, function(m, p1, offset, string) {
39+
return p1.replace(/\$/g, '\\$');
40+
});
41+
42+
re = /([^\\\$]|^)(\${1,2})(?!\$)(\s*)([\s\S]*?[^$])(\s*)(\2)(?!\2)/g;
43+
out = out.replace(re, function(m, p1, p2, p3, p4, p5, p6, offset, string) {
44+
return p1 + p2 + p3 + p4.replace(/(.)/g, '\\$1') + p5 + p6;
45+
});
46+
47+
return out;
48+
},
49+
50+
function ReEscapeTex(text) {
51+
var re = /([^\\\$]|^)(\${1,2})(?!\$)(\s*)([\s\S]*?[^$])(\s*)(\2)(?!\2)/g;
52+
var out = text.replace(re, function(m, p1, p2, p3, p4, p5, p6, offset, string) {
53+
return p1 + p2 + p3 + p4.replace(/\\(.)/g, '$1') + p5 + p6;
54+
});
55+
56+
return out;
57+
}
58+
59+
function PreviewDone() {
60+
this.isRunning[index] = false;
61+
Preview.forceUpdate = false;
62+
this.preview[index].innerHTML = this.buffer[index].innerHTML;
63+
}
64+
65+
function markjax(text, callback){
66+
var src = text.replace(/&lt;/mg, '<').replace(/&gt;/mg, '>');
67+
68+
var html = this.ReEscapeTex(marked(this.EscapeTex(src)));
69+
var code = $(html).find("code");
70+
for (var i = 0; i < code.length; i++) {
71+
code[i].innerHTML = code[i].innerHTML.replace(/\\\$/g, '$');
72+
}
73+
$(html).find("*").not("code").addClass("mathjax");
74+
75+
MathJax.Hub.Queue(
76+
["Typeset", MathJax.Hub, html],
77+
[callback, html],
78+
["resetEquationNumbers", MathJax.InputJax.TeX]
79+
);
80+
}
81+
82+
if (typeof module !== 'undefined' && typeof exports === 'object') {
83+
module.exports = markjax;
84+
} else if (typeof define === 'function' && define.amd) {
85+
define(function() { return markjax; });
86+
} else {
87+
this.markjax = markjax;
88+
}
89+
}).call(function() {
90+
return this || (typeof window !== 'undefined' ? window : global);
91+
}());

markjax.js

-211
This file was deleted.

package.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "markjax",
3+
"version": "1.0.0",
4+
"description": "Javascript parser for converting Markdown with LaTeX to HTML",
5+
"main": "./lib/markjax.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/codeassign/markjax.git"
12+
},
13+
"dependencies": {
14+
"mathjax": "latest",
15+
"marked": "latest",
16+
"jquery": "latest"
17+
},
18+
"keywords": [
19+
"parser",
20+
"markdown",
21+
"latex",
22+
"html"
23+
],
24+
"author": "CodeAssign Team <[email protected]> (http://codeassign.com)",
25+
"license": "Apache-2.0",
26+
"bugs": {
27+
"url": "https://github.com/codeassign/markjax/issues"
28+
},
29+
"homepage": "https://github.com/codeassign/markjax#readme"
30+
}

0 commit comments

Comments
 (0)