HTML Editor and Math Tags

HTML Editor and Math Tags

by Zbigniew Fiedorowicz -
Number of replies: 16

Hi Janne,

This is related to another discussion http://moodle.org/mod/forum/discuss.php?d=4742. We have introduced some new tags for marking up mathematical expression for use with filters. Some of the new tags are <algebra>.. </algebra>, <tex>..</tex>, <math>..</math>. Unfortunately it is impossible to enter these tags in the HTML Editor. If you enter these tags in WYSIWIG mode, the < and > are character encoded. If you enter them in source view mode, then they get converted as follows <tag> to <tag /> and </tag> to </tag />.  [Martin has modified weblib.php to recognize these tags.]

Zig

Average of ratings: -
In reply to Zbigniew Fiedorowicz

Re: HTML Editor and Math Tags

by Janne Mikkonen -

Hi Zig.

I think this is the part we'll have to change so it would recognize those tags you've added and leave them unencoded.

Starts from line 1828 in htmlarea.php
// performs HTML encoding of some given string
HTMLArea.htmlEncode = function(str) {
 // we don't need regexp for that, but.. so be it for now.
 str = str.replace(/&/ig, "&amp;");
 str = str.replace(/</ig, "&lt;");
 str = str.replace(/>/ig, "&gt;");
 str = str.replace(/\x22/ig, "&quot;");
 // \x22 means '"' -- we use hex reprezentation so that we don't disturb
 // JS compressors (well, at least mine fails.. ;)
 return str;
};

- Janne -

In reply to Janne Mikkonen

Re: HTML Editor and Math Tags

by Zbigniew Fiedorowicz -

Hi Janne,

I don't think I want to mess with HTMLArea.htmlEncode. There are two problems: first of all MathML has quite a lot of tags: see http://www.w3.org/TR/REC-MathML/chap3_1.html. Even more problematic is that sometimes we do want the <algebra>, etc. tags to be character encoded, for instance when explaining to students how to enter mathematical expressions.

What I would like is some GUI method in the editor to mark text as being in raw html "style", similar to the way of marking text as being "bold" or "italic".  Text which is marked as being in this raw html "style" would not be passed through HTMLArea.htmlEncode.

Zig

In reply to Zbigniew Fiedorowicz

Re: HTML Editor and Math Tags

by Zbigniew Fiedorowicz -

For what it's worth, here's the list of the MathML v.1.01 tags:

<math><mi><mn><mo><mtext><mspace><ms><mrow><mfrac><msqrt><mroot><mstyle><merror>
<mpadded><mphantom><mfenced><msub><msup><msubsup><munder><mover><munderover>
<mmultiscripts><mtable><mtr><mtd><maligngroup><malignmark><maction><cn><ci><apply><reln>
<fn><interval><inverse><sep><condition><declare><lambda><compose><ident><quotient><exp>
<factorial><divide><max><min><minus><plus><power><rem><times><root><gcd><and><or><xor>
<not><implies><forall><exists><abs><conjugate><eq><neq><gt><lt><geq><leq><ln><log><int>
<diff><partialdiff><lowlimit><uplimit><bvar><degree><set><list><union><intersect><in><notin>
<subset><prsubset><notsubset><notprsubset><setdiff><sum><product><limit><tendsto><mean>
<sdev><variance><median><mode><moment><vector><matrix><matrixrow><determinant>
<transpose><selector><annotation><semantics><annotation-xml>

In reply to Zbigniew Fiedorowicz

Re: HTML Editor and Math Tags

by Janne Mikkonen -

Hi Zig.

You really gave a real hard nut to crack. I'm not sure can this editor or any other editor handle those taggings (but we'll try).

- Janne -

In reply to Zbigniew Fiedorowicz

Re: HTML Editor and Math Tags

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
If it just treated those tags as normal paired tags and didn't try to change them all the time that would be a good start. It's not too bad to ask people to switch to source-editing mode when entering maths stuff (at least for the time being).
Trying some test tags in this post... maths degrees msub and stuff algebrastuff
Hmm ... I'm not getting the tags problem Zig is talking about. I've seen it before but I'm not seeing it now under Mozilla on Windows after many edits.
In reply to Martin Dougiamas

Re: HTML Editor and Math Tags

by Ger Tielemans -

I wrote about related problems:

  •  when I tricked the quizz.-module to place a figure next to a matching question
  • when I opened and closed a hotpotatoes exercise
  • when I used a piece of code for a choose your soundsample program

Everytime the problem is that the editor closes the tags, while products deliberatily leave the tag open,not nice but they do.. (just a button on the editor page to toggle editor on/off would be for this moment a good workaround:people trying these things are not Moodle-beginners)

In reply to Martin Dougiamas

Re: HTML Editor and Math Tags

by Zbigniew Fiedorowicz -
I am getting this problem with IE 6.0/WinXP under the following circumstance: enter <math> or <algebra> tags in source view, switch to normal edit mode, then either post or switch back again to source view.
In reply to Zbigniew Fiedorowicz

Re: HTML Editor and Math Tags

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
What about if you don't switch back to normal mode?
In reply to Martin Dougiamas

Re: HTML Editor and Math Tags

by Zbigniew Fiedorowicz -
Then it's fine.  However, if you want to enter several different mathematical expressions interspersed with normal text, you would want to switch back and forth between views.
In reply to Zbigniew Fiedorowicz

Re: HTML Editor and Math Tags

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Sure, of course. It's just good to know about workarounds. So we know now that this rewriting occurs when switching from source to normal mode.

It might be time to mention to Janne that the editor in Mozilla 1.6 currently won't allow me to switch back to normal mode from source mode. smile I can switch back and forth all day in fullscreen view but not in the default view (the switch button just lays there smirking at me)..
In reply to Martin Dougiamas

Re: HTML Editor and Math Tags

by Janne Mikkonen -
Yes, I know that you can't switch modes correctly in mozilla on windows platform (in linux this works fine).

And I can't find reason for that (event handling maybe?).

Seems like that Math tags issue just grew a little bit bigger?

Editor doesn't understand nothing more than regular HTML ( It closes single tags with XHTML -ending />) and since the HTML and XHTML are basically the same (tags) there are no problems.

If we're swinging back and forth with modes how can we indentify wich tags should be encoded and wich shouldn't? (Yipe!).

- Janne -


In reply to Janne Mikkonen

Re: HTML Editor and Math Tags

by Zbigniew Fiedorowicz -
How difficult would it be to implement the idea I suggested: have a <rawhtml>....</rawhtml> tag which keeps everything inside in source view mode always? So if you switched into source view mode, the only additional detail you would see is the <rawhtml> tags wrapped around it.
In reply to Zbigniew Fiedorowicz

Re: HTML Editor and Math Tags

by Janne Mikkonen -

A was sniffing about and find this: http://www1.chapman.edu/~jipsen/mathml/asciimath.xml

What do you think?

In reply to Janne Mikkonen

Re: HTML Editor and Math Tags

by Zbigniew Fiedorowicz -

Hi Janne,

Are you considering incorporating this into HTML Editor?  I haven't looked closely at his implementation, but it looks like a very nice idea.

Zig

In reply to Zbigniew Fiedorowicz

Re: HTML Editor and Math Tags

by Janne Mikkonen -

I'm not sure yet!

This is made by javascript wich been loaded with the page and it decodes those markings as a MathML.

I'm not so sure how it would be best to implement?
- Mix it with the editor or load the script when needed (when page includes a MathML header).

- Janne -

In reply to Janne Mikkonen

Re: HTML Editor and Math Tags

by Zbigniew Fiedorowicz -

Janne,

For these Javascripts to be useful, they would have to be always available in HTML Editor, not just be loaded when there is some special header in the page. For instance when posting to a forum. I gather that there is now a new API for user preferences, so perhaps the best approach would be to use that to decide whether on not to load the math Javascripts into HTML editor.

However, I think this is not something urgent which has to be done in the near future. What is much more urgent is to prevent HTML Editor from rewriting MathML, algebra and tex tags when switching in and out of source mode. Particularly for MathML, the way I envisage this being entered into Moodle for now is via copy and paste into the HTML Editor in source mode from some external editor or web page.

What do you think of my idea of wrapping text fragments with these tags in an extra set of tags, such as <rawhtml> ... </rawhtml>? HTML Editor would then look for these wrapper tags and preserve all the text inside these wrappers strictly intact. I think this would also provide at least a temporary fix for the conflict Ger Tielemans has between Hot Potatoes and HTML Editor.

Zig