Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mdc.renderer.rules.code_inline = function(tokens, idx) {
var code = tokens[idx].content;
if(code.startsWith('$') && code.endsWith('$')) { // inline math
code = code.substr(1, code.length-2);
try{
return katex.renderToString(code);
} catch(err) {
return '<code>' + err + '</code>';
}
}
return '<code>' + code + '</code>'; // not math
}
it('renders correctly', () => {
const math = shallow({ integralFormula });
expect(math.html()).to.equal(
`<${wrapperTag}>${ KaTeX.renderToString(integralFormula, { displayMode }) }`
);
});
var renderLatexString = function(s){
var renderedString;
try {
renderedString = katex.renderToString(s, options);
} catch (err){
console.error('couldn`t convert string', s);
return s;
}
return renderedString;
};
update: function (config, changes, obj) {
if (typeof(changes.text) !== 'undefined' && !changes.text.timeSeries) {
obj.domElement.innerHTML = katex.renderToString(changes.text, {displayMode: true});
changes.text = null;
}
if (typeof(changes.position) !== 'undefined' && !changes.position.timeSeries) {
obj.position.set(changes.position[0], changes.position[1], changes.position[2]);
obj.updateMatrixWorld();
changes.position = null;
}
if (areAllChangesResolve(changes)) {
return Promise.resolve({json: config, obj: obj});
} else {
return false;
}
let matches = regex.exec(katexString);
if (matchLocation > 0) {
numInline += 1;
while (matches !== null) {
try {
const renderedKatex = katex.renderToString(deHTMLify(matches[0].replace(/\$/g, '')));
text = `${text.replace(matches[0], ` ${renderedKatex}`)}`;
} catch {
numInline -= 1;
}
matches = regex.exec(katexString);
}
} else {
try {
text = katex.renderToString(deHTMLify(matches[2]));
} catch (error) {
numInline -= 1;
}
}
}
}
return [text, numInline > 0];
}
renderer.paragraph = (t) => {
generateHTML(text) {
const inlineHTML = katex.renderToString(text, {displayMode: false, throwOnError: false});
const displayHTML = katex.renderToString(text, {displayMode: true, throwOnError: false});
return {inlineHTML, displayHTML};
},
replace: function(text, group) {
try {
return katex.renderToString(group);
} catch (e) {
return group;
}
}
}
render ($$) {
const node = this.props.node
const texMath = node.textContent
const el = $$('span').addClass('sc-math')
if (!texMath) {
el.append('???')
} else {
try {
el.append(
$$('span').html(katex.renderToString(texMath))
)
let blockerEl = $$('div').addClass('se-blocker')
el.append(blockerEl)
} catch (error) {
el.addClass('sm-error')
.text(error.message)
}
}
return el
}
}
const outputKatexHTML = text.replace(/¨D¨D((.|\n)*?)¨D¨D/g, function(match, capture) {
const text = capture.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"').replace(/\n/g, '\r\n');
let html = katex.renderToString(text);
if (text.search('\n') !== -1) {
html = `<br>${html}`;
}
return html;
});
const processor = remark()
.use(math)
.use(remark2rehype)
.use(rehypeKatex, {
errorColor: 'orange',
macros: macros
})
.use(stringify)
const targetText = '$\\RR$'
const result = processor.processSync(targetText)
const renderedAst = parseHtml(result.toString())
const expectedInlineMathChildren = parseHtml(
katex.renderToString('\\RR', {macros: macros})
).children
expect(renderedAst).toEqual(
u('root', {data: {quirksMode: false}}, [
h('p', [h('span', {className: 'inlineMath'}, expectedInlineMathChildren)])
])
)
})