mirror of
https://github.com/discourse/discourse-math.git
synced 2025-07-04 12:52:18 +00:00
bug fixes
This commit is contained in:
parent
0ff9d65675
commit
84d7bfc02f
@ -24,6 +24,12 @@ function ensureMathJax(){
|
|||||||
|
|
||||||
function decorate(elem, isPreview){
|
function decorate(elem, isPreview){
|
||||||
const $elem= $(elem);
|
const $elem= $(elem);
|
||||||
|
|
||||||
|
if ($elem.data('applied-mathjax')){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$elem.data('applied-mathjax', true);
|
||||||
|
|
||||||
const tag = elem.tagName === "DIV" ? "div" : "span";
|
const tag = elem.tagName === "DIV" ? "div" : "span";
|
||||||
const display = tag === "div" ? "; mode=display" : "";
|
const display = tag === "div" ? "; mode=display" : "";
|
||||||
|
|
||||||
@ -36,7 +42,7 @@ function decorate(elem, isPreview){
|
|||||||
Em.run.later(this, ()=> {
|
Em.run.later(this, ()=> {
|
||||||
window.MathJax.Hub.Queue(() => {
|
window.MathJax.Hub.Queue(() => {
|
||||||
// don't bother processing previews removed from DOM
|
// don't bother processing previews removed from DOM
|
||||||
if (elem.parentElement.offsetParent !== null) {
|
if (elem.parentElement && elem.parentElement.offsetParent !== null) {
|
||||||
window.MathJax.Hub.Typeset($math[0], ()=> {
|
window.MathJax.Hub.Typeset($math[0], ()=> {
|
||||||
$elem.remove();
|
$elem.remove();
|
||||||
$mathWrapper.show();
|
$mathWrapper.show();
|
||||||
@ -51,6 +57,7 @@ function mathjax($elem) {
|
|||||||
|
|
||||||
if (mathElems.length > 0) {
|
if (mathElems.length > 0) {
|
||||||
const isPreview = $elem.hasClass('d-editor-preview');
|
const isPreview = $elem.hasClass('d-editor-preview');
|
||||||
|
|
||||||
ensureMathJax().then(()=>{
|
ensureMathJax().then(()=>{
|
||||||
mathElems.each((idx,elem) => decorate(elem, isPreview));
|
mathElems.each((idx,elem) => decorate(elem, isPreview));
|
||||||
});
|
});
|
||||||
|
@ -59,7 +59,7 @@ function inlineMath(state, silent) {
|
|||||||
|
|
||||||
if (found+1 <= posMax) {
|
if (found+1 <= posMax) {
|
||||||
let next = state.src.charCodeAt(found+1);
|
let next = state.src.charCodeAt(found+1);
|
||||||
if (!isSafeBoundary(next, state.md)) {
|
if (next && !isSafeBoundary(next, state.md)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,13 @@ describe PrettyText do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'can handle inline edge cases' do
|
it 'can handle inline edge cases' do
|
||||||
|
expect(PrettyText.cook ",$+500\\$").not_to include('math')
|
||||||
|
expect(PrettyText.cook "$+500$").to include('math')
|
||||||
expect(PrettyText.cook ",$+500$,").to include('math')
|
expect(PrettyText.cook ",$+500$,").to include('math')
|
||||||
expect(PrettyText.cook "200$ + 500$").not_to include('math')
|
expect(PrettyText.cook "200$ + 500$").not_to include('math')
|
||||||
expect(PrettyText.cook ",$+500\$x").not_to include('math')
|
expect(PrettyText.cook ",$+500$x").not_to include('math')
|
||||||
expect(PrettyText.cook "y$+500\$").not_to include('math')
|
expect(PrettyText.cook "y$+500$").not_to include('math')
|
||||||
expect(PrettyText.cook "($ +500 $)").to include('math')
|
expect(PrettyText.cook "($ +500 $)").to include('math')
|
||||||
expect(PrettyText.cook ",$+500\$").not_to include('math')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can handle inline math' do
|
it 'can handle inline math' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user