Posting / Commenting

Commenting

  • When you reply to a comment, to preserve threading structure, use the “reply” link just below that comment.
  • If you want to quote the comment you are replying to, use the “quote” link.
  • If you only want to quote part of the comment, select that text before using the “quote” link.
  • if you don’t like being represented by a randomly-generated wavatar, go to gravatar.com and associate your chosen image with the email address you are using for your posts here.
  • Initial comments are moderated. If you want us to approve the post, please make sure it says something that makes it look like you actually read the article. As much as we appreciate positive feedback, initial posts that just say “thanks for the great article” will probably be rejected, to avoid opening the door to spammers.

Markdown

In addition to supporting raw HTML, this site supports PHP Markdown Extra, a wiki-like format1, in posts and comments.

LaTeX formulas

Because we’re running a study group for the book Elements of Programming, which uses lots of formulas, we’ve installed a plugin that supports inline LaTeX. Please read its homepage if you want to embed LaTeX.

Syntax Highlighting

We have also applied a variant of this patch for nice syntax highlighting.

   ~~~
   void your_code_here();
   ~~~
  • C++ is the default language here; if you need to post a different GeSHi-supported language, begin your code with a line that reads:
   {{lang:GeSHi-language-id}}
  • For non-highlighted “code blocks,” you can use “txt” as the language id.
  • If you want line numbering, add
   {{lang:GeSHi-language-id, line:start-line-number}}

Markdown Plugin Patch

--- PHP Markdown Extra 1.2.4/markdown.php   2009-10-10 11:11:04.000000000 -0400
+++ PHP Markdown Extra 1.2.4 with Syntax Highlight and Header Level Adjustment/markdown.php 2010-02-09 13:31:28.000000000 -0500
@@ -11,6 +11,8 @@
 # <http://daringfireball.net/projects/markdown/>
 #
 
+include_once 'markdown-highlight.php';
+include_once 'wp-syntax/geshi/geshi.php';
 
 define( 'MARKDOWN_VERSION',  "1.0.1n" ); # Sat 10 Oct 2009
 define( 'MARKDOWNEXTRA_VERSION',  "1.2.4" ); # Sat 10 Oct 2009
@@ -931,12 +933,12 @@
        if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1]))
            return $matches[0];
 
-       $level = $matches[2]{0} == '=' ? 1 : 2;
+       $level = $matches[2]{0} == '=' ? 3 : 4;
        $block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level>";
        return "\n" . $this->hashBlock($block) . "\n\n";
    }
    function _doHeaders_callback_atx($matches) {
-       $level = strlen($matches[1]);
+       $level = strlen($matches[1]) + 2;
        $block = "<h$level>".$this->runSpanGamut($matches[2])."</h$level>";
        return "\n" . $this->hashBlock($block) . "\n\n";
    }
@@ -1113,7 +1115,7 @@
                )
                ((?=^[ ]{0,'.$this->tab_width.'}\S)|\Z) # Lookahead for non-space at line-start, or end of doc
            }xm',
-           array(&$this, '_doCodeBlocks_callback'), $text);
+           array(&$this, '_doCodeBlocks_highlight_callback'), $text);
 
        return $text;
    }
@@ -1130,6 +1132,21 @@
        return "\n\n".$this->hashBlock($codeblock)."\n\n";
    }
 
+   function _DoCodeBlocks_highlight_callback($matches) {
+       $codeblock = $matches[1];
+
+       $codeblock = $this->outdent($codeblock);
+
+       # trim leading newlines and trailing whitespace
+       $codeblock = preg_replace(array('/\A\n+/', '/\s+\z/'), '', $codeblock);
+
+       $codeblock = preg_replace_callback('/^(\{\{((lang:([\w]+)|line:([\d]+)) *(?(?!\}), *))+\}\}\n|)(.*?)$/s', 
+                                           create_function('$matches', '
+       return highlight_src($matches[6], empty($matches[4]) ? "cpp" : $matches[4], $matches[5]);
+       '), $codeblock);
+
+       return "\n\n".$this->hashBlock($codeblock)."\n\n";
+    }
 
    function makeCodeSpan($code) {
    #
@@ -2267,13 +2284,13 @@
    function _doHeaders_callback_setext($matches) {
        if ($matches[3] == '-' && preg_match('{^- }', $matches[1]))
            return $matches[0];
-       $level = $matches[3]{0} == '=' ? 1 : 2;
+       $level = $matches[3]{0} == '=' ? 3 : 4;
        $attr  = $this->_doHeaders_attr($id =& $matches[2]);
        $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>";
        return "\n" . $this->hashBlock($block) . "\n\n";
    }
    function _doHeaders_callback_atx($matches) {
-       $level = strlen($matches[1]);
+       $level = strlen($matches[1]) + 2;
        $attr  = $this->_doHeaders_attr($id =& $matches[3]);
        $block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$level>";
        return "\n" . $this->hashBlock($block) . "\n\n";
@@ -2565,10 +2582,27 @@
                # Closing marker.
                \1 [ ]* \n
            }xm',
-           array(&$this, '_doFencedCodeBlocks_callback'), $text);
+           array(&$this, '_doFencedCodeBlocksHighlight_callback'), $text);
 
        return $text;
    }
+   function _doFencedCodeBlocksHighlight_callback($matches) {
+       $codeblock = $matches[2];
+                // Look for language and starting line specifier in the form {{lang:xxx,line:nnn}}
+       $codeblock = preg_replace_callback(
+           '/^(\{\{((lang:([\w]+)|line:([\d]+)) *(?(?!\}), *))+\}\}\n|)(.*?)$/s', 
+
+                        // Build a function that will highlight the
+                        // code, defaulting to C++ highlights and no line
+                        // numbers.
+           create_function('$matches', '
+return highlight_src($matches[6], empty($matches[4]) ? "cpp" : $matches[4], $matches[5]);
+'
+                        ), 
+           $codeblock);
+
+       return "\n\n".$this->hashBlock($codeblock)."\n";
+   }
    function _doFencedCodeBlocks_callback($matches) {
        $codeblock = $matches[2];
        $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);

  1. N.B. the site’s theme uses <h1> and <h2>, but we’ve adjusted the markdown code to preserve site structure, so that top-level headers show up as <h3> header rather than an <h1>. So just write your markdown “naturally.”