Commenting

Feel free to comment on the content. But as always, be courteous.

When commenting, you can add code snippets by placing source code samples in HTML <code> tags. The source code will render in monospace font and
preserve any spacing you have introduced.

If you want to use the simple syntax highlighting, use the following attribute <code sourceType="language"> your code here

The language name should be all in lowercase. Currently highlighting is available for a handful of languages shown below. If your a language is not listed, you may still use the attribute. Eventually most languages will have some support.

Language Attr. Value
Java java
C/C++ cpp
HTML html
XML xml
JavaScript javascript

For example, here is an example of Java source code where we do not use the sourceType attribute:

public class Roster {
   private int      counter = 0;
   private String[] names = new String[50];
 
   public void addStudent(String newName) {
      // crazy hard code
   }
}

and here is the same code with but we set the value of the sourceType attribute to "java".

public class Roster {
   private int      counter = 0;
   private String[] names = new String[50];
 
   public void addStudent(String newName) {
      // crazy hard code
   }
}

The highlighting has some limitations but it does a reasonable job for the moment. Hopefully I'll have time to improve it as I go along.

Inline Code Text

You can also do inline code samples. The difference is whether or not the <code> tag appears after a new line or not. If you just place <code>some code text</code> in a paragraph, it's inline. If you hit the return key and then open a <code> element, it is formatted as a code snippet like the above. Inline code is not highlighted.

There are still some things to be worked out here. For example, to get the line

<code>some code text</code>

you cannot use nested <code> tags since the parser matches the first opening tag to the first closing tag. That is, the result of

<code><code>some code text</code></code>

(which is hand coded) is

<code>some code text

To get around this, use

<pre><code>some code text</code></pre>

(which is also hand coded).

Leave a Reply