views:

28

answers:

1

Are there any examples of using the YUI Editor to allow user to submit code snippets etc, like may be used in a bulletin board?. I am talking specifically, about an example that allows a user to apply syntax highlighting to sections of the submitted code, so that it is rendered (for example) as C++, PHP, Python code snippet.

The SO Editor (the one I am currently using to submit this question), has a basic form of syntax highlighting, where you can format a section of the text as code, as demonstrated below:

#include <example.hpp>

int main(int argc, char** argv[])
{
    // This is a comment
    fb = new FooBar();
    fb->doSomethingAlready();
    delete fb;
}

At the very least, I want to be able to highlight a section of submitted text as code (as I have done above) - USING the YUI Editor.

Better still, I would like to use a full syntax editor that recognizes keywords for a particular language etc. I am sure someone must have written an extension to do this sort of thing before. BUT If any of this is not possible using the YUI editor, maybe someone can suggest an alternative WYSIWYG editor that I may be able to use in place of the YUI editor?

A: 

I think this is what you're looking for

Matthew Smith
@matthew: thanks for replying. You must have misunderstood my question - apparently, so has everyone else, thats why no one has as yet, answered what I would have been a relatively easy question to answer. I will modify my question to make what I want more clear.
morpheous
Actually, I don't think I misunderstood at all. You're not going to get what you want without a little work (with YUI, at any rate). The link provides an example of creating a new button. From there you should be able to figure out how to use it to modify selected text rather than using a form. That will give you the simple form of what you want. Then you just need to write the syntax highlighting part, or better yet, just use http://alexgorbatchev.com/SyntaxHighlighter/
Matthew Smith