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); p_dataSetter = this.setGraphPreviewData.bind(this);
} }
if (!p_svgNode) { 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); p_dataSetter(p_id, p_timeStamp);
return; return;
} }
@ -182,6 +182,10 @@ class GraphPreviewer {
// Fix SVG with width and height being '100%'. // Fix SVG with width and height being '100%'.
fixSvgRelativeWidth(p_svgNode) { fixSvgRelativeWidth(p_svgNode) {
if (!p_svgNode) {
return;
}
if (p_svgNode.getAttribute('width').indexOf('%') != -1) { if (p_svgNode.getAttribute('width').indexOf('%') != -1) {
// Try maxWidth. // Try maxWidth.
if (p_svgNode.style.maxWidth && p_svgNode.style.maxWidth.endsWith('px')) { if (p_svgNode.style.maxWidth && p_svgNode.style.maxWidth.endsWith('px')) {

View File

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

View File

@ -164,7 +164,7 @@ class MarkdownIt extends VxWorker {
this.mdit.use(window['markdown-it-imsize.js']); 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'. // Support '::: alert-xxx \n contents \n :::\n'.
this.mdit.use(window.markdownitContainer, 'alert', { this.mdit.use(window.markdownitContainer, 'alert', {

View File

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

View File

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