Special characters in jsxgraph/STACK

27 views
Skip to first unread message

jouer...@gmail.com

unread,
Apr 27, 2024, 3:54:08 PM4/27/24
to JSXGraph
Hi,

Perhaps it may be a simple question, but I can't find the answer out there.

If I include a character like '<' or '&&' in my jsxgraph code, when I save it, it replaces it with the HTML code &lt;, and the script doesn't work.

Is there a way around this problem?

Javier

Cleon Teunissen

unread,
Apr 27, 2024, 7:38:24 PM4/27/24
to jsxg...@googlegroups.com
You are not providing enough information.

In Javascript '&&' is a logical operator, and '<' is a  comparison operator. When writing Javascript: If you use those operators according to Javascript syntax then obviously it will not be replaced with some HTML entity.

But you are referring to 'my jsxgraph code'. It could be that you are using that '&&' inside a jsxgraph element declaration, but then again maybe not.

So: unfortunately you haven't provided the information necessary to address your question.

Cleon

jouer...@gmail.com

unread,
Apr 28, 2024, 4:14:03 AM4/28/24
to JSXGraph
Hello Cleon.

First of all thank you for your reply.

I re-read my message and I see that I was indeed too abbreviated. I'm sorry for that.

The key is in the subject. I am working with jsxgraph inside the STACK package, which in turn works on top of Moodle.

The behaviour I am referring to I think is actually linked to Moodle. I write the code inside an editor box, and when I save Moodle filters the text and makes the change I am referring to. I can use the '<' character as part of html code, for example in <p>, but when it is 'alone', such as when using it as an operator in a Javascript expression, it replaces it with &lt;. The same happens with '&&', which is replaced by '&amp;&amp;'.

I think it's a Moodle security theme, although I don't know exactly.

I realise I'm bordering the off topic, but I think it's possible that there is someone on the forum who works with STACK and has found (and perhaps solved) this problem.
 
I will also look for a Moodle forum to raise the issue, but I fear that the percentage of Moodle users who have tried to use something like jsxgraph is very small, so I think they are less likely to understand my problem.

Best wishes,

Javier

jouer...@gmail.com

unread,
Apr 28, 2024, 10:51:35 AM4/28/24
to JSXGraph
By asking on the STACK forum I have obtained an indirect solution. (Thanks to Marc Peterfi, I don't know if he is in this forum)

I wanted to use colour: function(){return a < b ? 'red' : 'blue' }
Instead of using the expression a < b I can use the JSX.Math.lt(a,b) function and it works perfectly.

It doesn't solve Moodle's automatic substitution of special characters, but it solves my current problem.

Javier

Alfred Wassermann

unread,
Apr 28, 2024, 12:05:08 PM4/28/24
to JSXGraph
This is a very well known problem in moodle. The most stable approach is to switch the editor to "plain" - if this is enabled by the system.
Otherwise, like you already noted, there are JXG.Math functions for all necessary binary operators like <, <=, &&, ||, ... by JSXGraph. See the API docu
for more information.

Best wishes,
Alfred


Reply all
Reply to author
Forward
0 new messages