Posting Code Snippets to the forum

Posted by jeff.griffiths on 2006-11-30 15:08
OS: All / Any | Product: Komodo
Question: 

How do I format code snippets in my Forum posts?

Answer: 

There are a couple of different ways to do this currently, each with their own use:

1. Inline code. If you just want to style something in fixed font inside a paragraph, use the <code/> tag. Example:

This:

This is my <code>Inline code sample</code> right here.

...will get you this:

This is my Inline code sample right here.

2. Blocks of fixed text. If you just want to dump in a block of fixed text with no special styling (for example, a log file excerpt) use the pre tag with the css class of 'code'. Example:

This:

<pre class="code">
komodo.view.setFocus();
try {
    komodo.editor.wordLeftExtend();
    var snippet = komodo.interpolate('%s');
    var tmpl = komodo.findPart("snippet", snippet, "container");
    if(tmpl) {
        Snippet_insert(tmpl);
    } else {
        var msg = "no snippet found named " + snippet;
        StatusBar_AddMessage(msg,"debugger",5000,true);
    }
} catch(e) {
    alert(e);
}
</pre>

Will give you this:

komodo.view.setFocus();
try {
    komodo.editor.wordLeftExtend();
    var snippet = komodo.interpolate('%s');
    var tmpl = komodo.findPart("snippet", snippet, "container");
    if(tmpl) {
        Snippet_insert(tmpl);
    } else {
        var msg = "no snippet found named " + snippet;
        StatusBar_AddMessage(msg,"debugger",5000,true);
    }
} catch(e) {
    alert(e);
}

collin | Thu, 2006-12-21 11:36

i looked at this faq because i was just about to post a realy neat code snippet.
now have a guess at what the snippets functionality was...
has this been made public anywhere?
i see quite a lot of complaining on the net regarding komodos inability
to do exactly what a macro containing above code does.

jeff.griffiths | Wed, 2006-12-27 12:21

Do you mean this blog post:

http://blogs.activestate.com/jeffg/2006/08/textmatestyle_m.html

--
JeffG | Komodo 4.0 Beta | MacBook Pro OS X Intel / Ubuntu 6.06 i386