Fix (partly) mathjax parsing

parent e3f71ff9
Pipeline #10720 passed with stages
in 2 minutes and 53 seconds
......@@ -80,7 +80,7 @@
"lodash": "4.17.4",
"memory-fs": "0.4.1",
"node-modules-path": "1.0.1",
"node-sass": "4.7.1",
"node-sass": "4.7.2",
"nopt": "4.0.1",
"opn": "5.1.0",
"portfinder": "1.0.13",
......@@ -571,7 +571,7 @@
"dev": true
},
"arsnova-click-v2-types": {
"version": "git+https://git.thm.de/arsnova/arsnova-click-v2-types.git#a1844e9b34300833e82fc968f728749481e1f4e6",
"version": "git+https://git.thm.de/arsnova/arsnova-click-v2-types.git#bbd3afaec4f65b4eeb9dbd04d99d4826f8b0e797",
"dev": true
},
"asap": {
......@@ -5491,7 +5491,7 @@
"ncname": "1.0.0",
"param-case": "2.1.1",
"relateurl": "0.2.7",
"uglify-js": "3.1.9"
"uglify-js": "3.1.10"
}
},
"html-webpack-plugin": {
......@@ -7329,9 +7329,9 @@
"dev": true
},
"make-plural": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/make-plural/-/make-plural-3.0.6.tgz",
"integrity": "sha1-IDOgO6wpC487uRJY9lud9+iwHKc=",
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/make-plural/-/make-plural-4.1.1.tgz",
"integrity": "sha512-triaMVDDYiB+OU1Mz6ht74+z0Bb/bzNESeMwRboSprI3GRWbOvfxEnpWI0eDixQtMPrC2C0revd4wmuck5GcoQ==",
"requires": {
"minimist": "1.2.0"
}
......@@ -7444,12 +7444,12 @@
}
},
"messageformat": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/messageformat/-/messageformat-1.0.2.tgz",
"integrity": "sha1-kI9GkfKf8o2uNcRUNqJM/5NAI4g=",
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/messageformat/-/messageformat-1.1.0.tgz",
"integrity": "sha512-0Pw6VMOzuWTorRwGXyY0oeosd6zlTykYYHMNJtK4bOwc/1G7yqr3mSg1fd822nKpBcN6J3YvdTKC4TRWsl/fqw==",
"requires": {
"glob": "7.0.6",
"make-plural": "3.0.6",
"make-plural": "4.1.1",
"messageformat-parser": "1.1.0",
"nopt": "3.0.6",
"reserved-words": "0.1.2"
......@@ -7824,9 +7824,9 @@
"dev": true
},
"node-sass": {
"version": "4.7.1",
"resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.7.1.tgz",
"integrity": "sha512-WUG10FNj6E3bXpAy7f3bXVdLVUJuNn8pRbT4oo5ez9Zp5ZfqPFKsVJuDEEUmkpdyGa8P9JwifEr5dhNgZT2FpQ==",
"version": "4.7.2",
"resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.7.2.tgz",
"integrity": "sha512-CaV+wLqZ7//Jdom5aUFCpGNoECd7BbNhjuwdsX/LkXBrHl8eb1Wjw4HvWqcFvhr5KuNgAk8i/myf/MQ1YYeroA==",
"dev": true,
"requires": {
"async-foreach": "0.1.3",
......@@ -8518,9 +8518,9 @@
}
},
"popper.js": {
"version": "1.12.9",
"resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.12.9.tgz",
"integrity": "sha1-DfvC3/lsRRuzMu3Pz6r1ZtMx1bM="
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.13.0.tgz",
"integrity": "sha1-4ef/ZcxD98+c8W8VEKdegfhPRWU="
},
"portfinder": {
"version": "1.0.13",
......@@ -11376,9 +11376,9 @@
"dev": true
},
"uglify-js": {
"version": "3.1.9",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.1.9.tgz",
"integrity": "sha512-ari2E89bD7f+fMU173NgF12JBcOhgoxeyuCs97h5K58IBENrnG9eVj2lFadrOPdqf0KifsxVmUQfzA2cHNxCZQ==",
"version": "3.1.10",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.1.10.tgz",
"integrity": "sha512-0ul3BWx79We0mIPM1l72oqpMtWL0TVMnKZZY6FaHPy3tDzCZGXeFxw5N1ZvtkmQsLI+ECR/tUQyIYbyHUcuvEw==",
"dev": true,
"requires": {
"commander": "2.11.0",
......
......@@ -29,9 +29,9 @@ export class QuestionTextService {
if (this._inputCache[value]) {
return new Promise((resolve => resolve(this._inputCache[value])));
}
const matchForDollar = value.match(/( ?\${1,2}\s.*)/g);
const matchForDollar = value.match(/( ?\${1,2}.*\$)/g);
const matchForBlock = value.match(/(\\(.)*\\.*)/g);
let result = '';
let result = value;
let mathjaxValues = [];
if (matchForDollar) {
mathjaxValues = mathjaxValues.concat(matchForDollar);
......@@ -40,20 +40,18 @@ export class QuestionTextService {
mathjaxValues = mathjaxValues.concat(matchForBlock);
}
result = parseGithubFlavoredMarkdown(value);
return new Promise((resolve) => {
if (mathjaxValues.length) {
this.parseMathjax(mathjaxValues).then((mathjaxRendered) => {
mathjaxValues.forEach((mathjaxValue: string, index: number) => {
// Escape the mathjax html characters so that we can find it in the parsed output of marked
const escapedMathjaxValue = mathjaxValue.replace(/&/g, '&')
.replace(/\\\\/g, '\\');
result = result.replace(escapedMathjaxValue, mathjaxRendered[index].svg);
result = result.replace(mathjaxValue, mathjaxRendered[index].svg);
});
result = parseGithubFlavoredMarkdown(result);
this._inputCache[value] = result;
resolve(result);
});
} else {
result = parseGithubFlavoredMarkdown(result);
this._inputCache[value] = result;
resolve(result);
}
......
......@@ -2,19 +2,21 @@ import marked from 'marked';
import highlight from 'highlight.js';
export function parseGithubFlavoredMarkdown(value: string): string {
marked.setOptions({
renderer: new marked.Renderer(),
const renderer = new marked.Renderer();
const options = {
renderer: renderer,
gfm: true,
tables: true,
breaks: true,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: true,
pedantic: true,
sanitize: false,
smartLists: false,
smartypants: false,
highlight: function (code) {
return highlight.highlightAuto(code).value;
}
});
};
marked.setOptions(options);
return postMarkdownRenderer(marked(preMarkdownRenderer(value)));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment