support equation begin in MathJax

This commit is contained in:
Le Tan 2021-12-04 17:47:51 +08:00
parent 04a93de5a5
commit 956842f102
5 changed files with 29 additions and 33 deletions

View File

@ -143,7 +143,7 @@ class GraphPreviewer {
p_dataSetter = this.setGraphPreviewData.bind(this);
}
if (!p_svgNode) {
console.error('failed to preview graph', p_id, p_timeStamp);
console.warn('failed to preview graph', p_id, p_timeStamp);
p_dataSetter(p_id, p_timeStamp);
return;
}
@ -182,6 +182,10 @@ class GraphPreviewer {
// Fix SVG with width and height being '100%'.
fixSvgRelativeWidth(p_svgNode) {
if (!p_svgNode) {
return;
}
if (p_svgNode.getAttribute('width').indexOf('%') != -1) {
// Try maxWidth.
if (p_svgNode.style.maxWidth && p_svgNode.style.maxWidth.endsWith('px')) {

View File

@ -186,19 +186,19 @@ texmath.$_post = (str,end) => {
texmath.rules = {
brackets: {
inline: [
{ name: 'math_inline',
{ name: 'math_brackets_inline',
rex: /\\\((.+?)\\\)/gy,
tmpl: '<eq class="tex-to-render">$1</eq>',
tag: '\\('
}
],
block: [
{ name: 'math_block_eqno',
{ name: 'math_brackets_block_eqno',
rex: /\\\[(((?!\\\]|\\\[)[\s\S])+?)\\\]\s*?\(([^)$\r\n]+?)\)\s*$/gmy,
tmpl: '<section class="eqno"><eqn class="tex-to-render">$1</eqn><span>($2)</span></section>',
tag: '\\['
},
{ name: 'math_block',
{ name: 'math_brackets_block',
rex: /\\\[([\s\S]+?)\\\]\s*$/gmy,
tmpl: '<section><eqn class="tex-to-render">$1</eqn></section>',
tag: '\\['
@ -207,19 +207,19 @@ texmath.rules = {
},
gitlab: {
inline: [
{ name: 'math_inline',
{ name: 'math_gitlab_inline',
rex: /\$`(.+?)`\$/gy,
tmpl: '<eq class="tex-to-render">$1</eq>',
tag: '$`'
}
],
block: [
{ name: 'math_block_eqno',
{ name: 'math_gitlab_block_eqno',
rex: /`{3}math\s*([^`]+?)\s*?`{3}\s*\(([^)\r\n]+?)\)/gm,
tmpl: '<section class="eqno"><eqn class="tex-to-render">$1</eqn><span>($2)</span></section>',
tag: '```math'
},
{ name: 'math_block',
{ name: 'math_gitlab_block',
rex: /`{3}math\s*([^`]*?)\s*`{3}/gm,
tmpl: '<section><eqn class="tex-to-render">$1</eqn></section>',
tag: '```math'
@ -228,12 +228,12 @@ texmath.rules = {
},
julia: {
inline: [
{ name: 'math_inline',
{ name: 'math_julia_inline',
rex: /`{2}([^`]+?)`{2}/gy,
tmpl: '<eq class="tex-to-render">$1</eq>',
tag: '``'
},
{ name: 'math_inline',
{ name: 'math_julia_inline',
rex: /\$((?:\S?)|(?:\S.*?\S))\$/gy,
tmpl: '<eq class="tex-to-render">$1</eq>',
tag: '$',
@ -242,12 +242,12 @@ texmath.rules = {
}
],
block: [
{ name: 'math_block_eqno',
{ name: 'math_julia_block_eqno',
rex: /`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)\s*$/gmy,
tmpl: '<section class="eqno"><eqn class="tex-to-render">$1</eqn><span>($2)</span></section>',
tag: '```math'
},
{ name: 'math_block',
{ name: 'math_julia_block',
rex: /`{3}math\s+?([^`]+?)\s+?`{3}\s*$/gmy,
tmpl: '<section><eqn class="tex-to-render">$1</eqn></section>',
tag: '```math'
@ -256,19 +256,19 @@ texmath.rules = {
},
kramdown: {
inline: [
{ name: 'math_inline',
{ name: 'math_kramdown_inline',
rex: /\${2}(.+?)\${2}/gy,
tmpl: '<eq class="tex-to-render">$1</eq>',
tag: '$$'
}
],
block: [
{ name: 'math_block_eqno',
{ name: 'math_kramdown_block_eqno',
rex: /\${2}([^$]+?)\${2}\s*?\(([^)\s]+?)\)\s*$/gmy,
tmpl: '<section class="eqno"><eqn class="tex-to-render">$1</eqn><span>($2)</span></section>',
tag: '$$'
},
{ name: 'math_block',
{ name: 'math_kramdown_block',
rex: /\${2}([^$]+?)\${2}\s*$/gmy,
tmpl: '<section><eqn class="tex-to-render">$1</eqn></section>',
tag: '$$'
@ -277,7 +277,7 @@ texmath.rules = {
},
dollars: {
inline: [
{ name: 'math_inline_double',
{ name: 'math_dollars_inline_double',
rex: /\${2}((?:\S)|(?:\S.*?\S))\${2}/gy,
tmpl: '<section><eqn class="tex-to-render">$1</eqn></section>',
tag: '$$',
@ -285,7 +285,7 @@ texmath.rules = {
pre: texmath.$_pre,
post: texmath.$_post
},
{ name: 'math_inline',
{ name: 'math_dollars_inline',
rex: /\$((?:\S)|(?:\S.*?\S))\$/gy,
tmpl: '<eq class="tex-to-render">$1</eq>',
tag: '$',
@ -294,13 +294,13 @@ texmath.rules = {
}
],
block: [
{ name: 'math_block_eqno',
rex: /\${2}([^$]+?)\${2}\s*?\(([^)\s]+?)\)\s*$/gmy,
{ name: 'math_dollars_block_eqno',
rex: /\${2}((?:[^$]|\$(?!\$))+?)\${2}\s*?\(([^)\s]+?)\)\s*$/gmy,
tmpl: '<section class="eqno"><eqn class="tex-to-render">$1</eqn><span>($2)</span></section>',
tag: '$$'
},
{ name: 'math_block',
rex: /\${2}([^$]+?)\${2}\s*$/gmy,
{ name: 'math_dollars_block',
rex: /\${2}((?:[^$]|\$(?!\$))+?)\${2}\s*$/gmy,
tmpl: '<section><eqn class="tex-to-render">$1</eqn></section>',
tag: '$$'
}
@ -310,7 +310,7 @@ texmath.rules = {
inline: [],
block: [
{
name: 'math_block',
name: 'math_raw_block',
rex: /(\\begin\s*\{([^{}\s\r\n]+)\}(?:[^\\]|\\(?!end\s*\{\2\}))*\\end\s*\{\2\})\s*$/gmy,
tmpl: '<section><eqn class="tex-to-render">$1</eqn></section>',
tag: '\\begin'

View File

@ -164,7 +164,7 @@ class MarkdownIt extends VxWorker {
this.mdit.use(window['markdown-it-imsize.js']);
this.mdit.use(texmath, { delimiters: ['dollars', 'raw'] });
this.mdit.use(texmath, { delimitersList: ['dollars', 'raw'] });
// Support '::: alert-xxx \n contents \n :::\n'.
this.mdit.use(window.markdownitContainer, 'alert', {

View File

@ -178,6 +178,8 @@ class MathJaxRenderer extends VxWorker {
display = true;
} else if (text.startsWith('$') && text.endsWith('$')) {
text = text.substring(1, text.length - 1);
} else if (text.match(/^\\begin\s*\{\S+}[\s\S]+\\end\s*\{\S+\}$/)) {
display = true;
} else {
return null;
}

View File

@ -131,10 +131,6 @@ void MarkdownViewWindow::setModeInternal(ViewWindowMode p_mode, bool p_syncBuffe
case ViewWindowMode::Edit:
{
if (m_debugViewer && m_debugViewer->isVisible()) {
toggleDebug();
}
if (!m_editor) {
// We need viewer to preview.
if (!m_viewer) {
@ -325,13 +321,7 @@ void MarkdownViewWindow::setupToolBar()
addAction(toolBar, ViewWindowToolBarHelper::FindAndReplace);
addAction(toolBar, ViewWindowToolBarHelper::Print);
{
auto act = addAction(toolBar, ViewWindowToolBarHelper::Debug);
connect(this, &ViewWindow::modeChanged,
this, [this, act]() {
act->setEnabled(m_mode == ViewWindowMode::Read || m_editViewMode != MarkdownEditorConfig::EditViewMode::EditOnly);
});
}
addAction(toolBar, ViewWindowToolBarHelper::Debug);
}
void MarkdownViewWindow::setupTextEditor()