-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: wrong parsing for math #929
Comments
See also #936 |
You shouldn't put LaTeX math formula in markdown, since they are not supported and are instead interpreted as markdown. If you want to keep the latex code as is, wrap it inside a
This is not a bug |
Adding this to the 0.5.0 miestone as math is something that comes up quite a bit, but does not seem to specifically addressed in the specifications we are focusin on (see #956). Closing. |
It's rude but solved my problem in a way... function replace(content, regx) {
content = content.replace(regx,
function(expression) {
var max_formula_length = 200;
if (expression.length > max_formula_length || has_chinese(expression)) return result;
expression = expression.replace(/\\\\/g, '\\\\\\\\');
expression = expression.replace(/\\ /g, '\\\\ ');
expression = expression.replace(/\\%/g, '\\\\%');
expression = expression.replace(/\\{/g, '\\\\{');
expression = expression.replace(/\\}/g, '\\\\}');
expression = expression.replace(/\\#/g, '\\\\#');
expression = expression.replace(/\\~/g, '\\\\~');
expression = expression.replace(/\\_/g, '\\\\_');
expression = expression.replace(/\\&/g, '\\\\&');
expression = expression.replace(/\\\$/g, '\\\\$');
expression = expression.replace(/\\\^/g, '\\\\^');
expression = expression.replace(/\\\|/g, '\\\\|');
expression = expression.replace(/\_/g, '\\_');
return expression;
});
return content;
}
var data = replace(raw_data, /\$\$([\s\S]*?)\$\$/gm);
data = replace(data, /\$([\s\S]*?)\$/gm);
data = marked(data); For example: var raw_data = '$$\\mathcal{L}_C=\\frac{1}{2} \\sum_{i=1}^{m} \\| x_i-c_{y_i} \\|_2^2$$';
var data = replace(raw_data, /\$\$([\s\S]*?)\$\$/gm);
data = replace(data, /\$([\s\S]*?)\$/gm);
data = marked(data);
console.log(data); output: <p>$$\mathcal{L}_C=\frac{1}{2} \sum_{i=1}^{m} \| x_i-c_{y_i} \|_2^2$$</p> It will be effective even for multi-line math formula. |
marked version: 0.3.6
My markdown code:
$B_{p_{1}}+B_{p_{2}}$
But when I try to parse into HTML using
$('#content').html(marked(mdString));
It returns wrong HTML code. Unexpected
<em></em>
occurred:<p>$B<em>{p</em>{1}}+B<em>{p</em>{2}}$</p>
The text was updated successfully, but these errors were encountered: