highlighting code

highlighting code

by Sandy Pittendrigh -
Number of replies: 4
It's possible this question doesn't belong in the developers forum.
But I am a PHP developer and I couldn't see where else to put it.

I am developing a Moodle course teaching elementary PHP programming
and web development.

When I use the built in ajax editor to write example code, the editor
strips out my indenting, which makes my example code difficult to read.
I can toggle the editor to source mode, but that is annoyingly difficult
to read and use because newlines are not interpreted. So the code looks
like one giant-long string, with no spaces at all.

Is there a way to use the editor, so it will add nbsp; spaces where needed?
I tend to jump out to my own CMS generated pages for resources (because of the above spacing problems), but I cannot do that on forums. And I don't want to have
to start writing sql update code to fix it.

Average of ratings: -
In reply to Sandy Pittendrigh

Re: highlighting code

by Sandy Pittendrigh -
Ah, ok, there is a highlight filter.
I'll dope that out.
In reply to Sandy Pittendrigh

Re: highlighting code

by Sandy Pittendrigh -
Now I'm responding to myself again.

The geshi filter does not work for me.
I need to be able to display PHP source code on HTML pages
and inside a forum. In both cases I'm out of luck right now.
I see from various posts I'm not the only one.

So, as a result, I jump out of moodle for all resource pages, where
I use my own CMS for page display. The forum is trickier.
I have a small files-based forum I wrote myself, that displays code
just fine. But maintenance is a little more demanding. I may have
to look around for a different forum to jump out to.

Either way, at that point I'm hardly using moodle anymore, for much
beyond login authentication. And I have my own stuff for that too.

Moodle needs to get the PHP source code issue fixed.
It's sadly ironic, that Moodle (written in PHP) cannot be used
to teach PHP. I'd be happy to try to help, but I don't have time
to take a leadership role in this.


In reply to Sandy Pittendrigh

Re: highlighting code

by Martín Langhoff -
Moodle can be used to teach PHP - definitely!

It should display PHP code correctly. We use this often in this very forum. If you are having a problem with that, be clearer in what you are trying and what is going wrong. Steps-to-repro.

It will not execute PHP that users post or upload, that is a matter of security. A lot of PHP teachers complain about this... It may be a good idea to teach your students about good security practices to stop SQL injections, CSRF and XSS. You can even use Moodle's refusal to execute PHP code as a positive example big grin
In reply to Martín Langhoff

Re: highlighting code

by Martín Langhoff -

Just to test geshi magic...

<?php
/* multi
   line
   comment! */
myphpfunction('somestring');
$object->method(1, "<-that's an int!");
// Is LOLCode supporteD?
$str = "can I haz interpolated $variablez ?";

foreach $ping as $pang {
    $keep = "my indentation plz";
}   

?>

Note: I disable the html editor and use markdown. Which means all I need to do to my code blocks is prefix them with 4 spaces.

But I think htmlarea has a way to mark parts of the content as "code". Can't remember how though mixed