Notifications
Clear all

wpForo 1.x.x [Solved] Q&A schema problem with LaTex content

11 Posts
3 Users
0 Reactions
1,107 Views
xfok
Posts: 86
 xfok
Topic starter
(@xfok)
Estimable Member
Joined: 5 years ago

First of all thank you for adding the Q&A schema in wpForo, a nice update. However, in some questions an error is recognized. I attach an image to make it clear.

 

10 Replies
Robert
Posts: 10591
Admin
(@robert)
Support Team
Joined: 9 years ago

Hi @xfok,

This is not a bug. I think you have some specific content in the post which has crashed the JS syntax. I'd recommend check other topics, and please report the errors in English. 

5 Replies
xfok
 xfok
(@xfok)
Joined: 5 years ago

Estimable Member
Posts: 86

@robert

Yes, in questions where Latex is used (mathematical writing) it is not recognized. The error reported is the following: Empty escape sequence in string

It is possible to somehow reach this error, being a mathematics site on 6000 questions about 4000 make use of Latex so most of them will not be validated by the Q&A scheme

Robert
Admin
(@robert)
Joined: 9 years ago

Support Team
Posts: 10591

@xfok ,

Ok, then we can filter that, there is a filter hook on the scheme which can help us. Please leave a direct link to that topic, so I can suggest you a fixing hook code.

Robert
Admin
(@robert)
Joined: 9 years ago

Support Team
Posts: 10591

As far as I see we just need to remove the backslashes or escape them with new backslashes from the body of question scheme in this case the JSON parsing will work and there will not be any error on validation. So just leave a URL to that topic, so we could see the syntax issues.  

xfok
 xfok
(@xfok)
Joined: 5 years ago

Estimable Member
Posts: 86

@robert 

https://www.sosmatematica.it/forum/domande/calcolare-il-momento-magnetico-di-una-particella/

dimalifragis
(@dimalifragis)
Joined: 5 years ago

Famed Member
Posts: 2611

@xfok All i see in the above are errors from peepso-groups

 

Uncaught TypeError: t.group is undefined
    [1]</</<  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    [1]</<  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    [1]<  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    d  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    d  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    [2]</</<  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    [2]</<  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    [2]<  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    d  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    d  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    [4]<  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    d  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    d  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    [5]<  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    d  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    a  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
    <anonymous>  https://www.sosmatematica.it/wp-content/plugins/peepso-groups/assets/js/page-group.min.js?mt=1622629596&ver=3.4.0.4:1 
Robert
Posts: 10591
Admin
(@robert)
Support Team
Joined: 9 years ago

All is clear, the Latex raw content has some back-slashes, and they crash the JSON syntax. The content should be filtered. Please let me know which Latex plugin do you use: https://wordpress.org/plugins/tags/latex/

3 Replies
xfok
 xfok
(@xfok)
Joined: 5 years ago

Estimable Member
Posts: 86

@robert simple mathjax https://it.wordpress.org/plugins/simple-mathjax/

Robert
Admin
(@robert)
Joined: 9 years ago

Support Team
Posts: 10591

Ok, thank you, @xfok,

This hook code should fix the issue. Please put this code in the functions.php file of your current active WordPress theme, delete all caches and check it again:

add_filter('wpforo_seo_meta_tags', 'wpforo_latext_filter_for_seo_tags');
function wpforo_latext_filter_for_seo_tags( $content ){
$pth = array( '|\$\$|', '|\$(\p{L})|u', '|(\p{L})\$|u', '|\\\text\{([^\}]+)\}|', '|\}\$|', '|\$\\\|', '|\\\pm|', '|\\\times|', '|\\\div|', '|\\\mathrm\{~?(\w{1,3})\}|', '|\\\Rightarrow|', '|\\\Leftarrow|', '|\\\cdot|', '|\\\right\)|', '|\\\left\(|', '|=\$\$=|', '|\\\(\p{L}+)\s?|', '|\\\|' );
$rep = array( ' ', '$1', '$1', ' $1 ', '}', '\\', '+/-', 'x', '/', '$1', '=>', '<=', '.', ')', '(', ' = ', ' $1 ', '' );
$content_fixed = preg_replace($pth, $rep, $content);
if( $content_fixed ) return $content_fixed;
return $content;
}
xfok
 xfok
(@xfok)
Joined: 5 years ago

Estimable Member
Posts: 86

@robert Thank you so much, fantastic support. The problem seems to be solved! 😊