Lessons about HTML/JavaScript

Lessons about HTML/JavaScript

by Stefaan Plets -
Number of replies: 7
I'm trying to make some lessons about HTML and JavaScript, but I'm experiencing difficulties with the formatting of the code fragments.  For instance, when I copy/paste from Word into the WYSIWYG editor, I get extra lines between the instructions; when I use a default HTML-form to edit, the code fragments get "interpreted", and so on.
Does anyone have some experience with the inclusion of code fragments in lesson pages?  Is there an easy way to get some nice formatting (perhaps some background color, border around fragment...)???
In my class room, I often use MoinMoin Wiki.  There you can put code fragments between {{{ and }}}.  Is there something similar in Moodle?

Many thanks for every hint...
Average of ratings: -
In reply to Stefaan Plets

Re: Lessons about HTML/JavaScript

by Richard Watkins -

I don't get this problem, I've just written the following in Word and pasted it into here:

Test code

<html>

<body>

</body>

</html>

It seems to have put tons of MS styles in though sad

Have you tried pasting into Notepad or something similar and copy/pasting from there?

Annoying, but it might solve the problem.

In reply to Richard Watkins

Re: Lessons about HTML/JavaScript

by Stefaan Plets -

For the moment, the detour via Notepad seems to be the best solution:  this becomes something like:
</p><p>&lt;html&gt;<br />&lt;body&gt;<br />&lt;script type=&quot;text/javascript&quot;&gt;<br />document.write(&quot;Hello World!&quot;)<br />&lt;/script&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</p>

Or: separate lines become divided by <br> tags.

If I paste directly from Word, en then use the Clean Word HTML button, the lines get separated by <p> - tags, and so there's too much distance between them...

</p><p>&lt;html&gt; </p><p>&lt;body&gt; </p><p>&lt;script type=&quot;text/javascript&quot;&gt; </p><p>document.write(&quot;Hello World!&quot;) </p><p>&lt;/script&gt; </p><p>&lt;/body&gt; </p><p>&lt;/html&gt; </p>

In reply to Stefaan Plets

Re: Lessons about HTML/JavaScript

by Bryan Williams -
As you may know, Word (and most MS products) put a lot of crap into HTML that can cause problems.  Notice in Moodles HTML editor an icon in the upper right corner with a W on it.  This does a good job in removing Word specific tags. 
In reply to Bryan Williams

Re: Lessons about HTML/JavaScript

by koen roggemans -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Translators

Aha, that's where the icon is for. I'll have to file a bug, because the tooltip isn't translatable. Thanks!

In reply to Stefaan Plets

Re: Lessons about HTML/JavaScript

by Ger Tielemans -

workaround: type the code with spaces between every letter:

< h t m l > < c o d e > o n c l i c k Hello < / c o d e > < / h t m l>


example where moodle put s the extra X before Xonclick;

< I N P U T o n c l i c k = " R u n P r o g ( ' E x c e l ' ) " t y p e = ' b u t t o n ' v a l u e = ' p u s h m e ' >
< S C R I P T  l a n g u a g e = V B S c r i p t >
s u b  R u n P r o g ( C o m m a n d L i n e )
D i m  O b j S h e l l
S e t  O b j S h e l l  =  C r e a t e O b j e c t ( " W S c r i p t . S h e l l ")
e r r o r s t a t e = O b j S h e l l . R u n ( C o m m a n d L i n e , 1 , F a l s e )
' D e s t r o y  C o m m a n d  l i n e  o b j e c t
S e t O b j S h e l l  = N o t h i n g
e n d  s u b
< / S C R I P T >

In reply to Stefaan Plets

Re: Lessons about HTML/JavaScript

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
Normally nothing special is needed, because it Just Works.

<script language="JavaScript">
<!-- //hide

function popUpProperties(inobj) {
op = window.open();
op.document.open('text/plain');
for (objprop in inobj) {
op.document.write(objprop + ' => ' + inobj[objprop] + '\n');
}
op.document.close();
}

// done hiding -->
</script>

Word is probably a special case when used with IE, due the integration in Windows.

In reply to Martin Dougiamas

Re: Lessons about HTML/JavaScript

by Ray Kingdon -
...and as Bryan indelicately said the c#@p is adds big grin. It puts some awful stuff in there.