#!/usr/bin/perl # Blosxom Plugin: coderpants # Author(s): Eric Sherman blocks in the tradition of the smartypants # and textile plugins. # # Just make sure it loads before textile and read the comments below. package coderpants; # --- Meta variables ------------- # meta-coderpants_enable: enables the plugin for this story if set to anything # meta-coderpants_disable: disables the plugin for this story if set to anything # --- Configurable variables ----- # should this plugin usually be turned on? # 1 = yes, 0 = no $auto_enable = 1; # the head and foot of an inline code block, usually used for one variable or # a short phrase which should appear in the same line as other text. # surrounded by @ signs, with the contents touching the signs. # ex: ...this @template@ activates when @$blosxom::flavour eq 'html'@ so... # becomes (by default): ...this template activates when $blosxom::flavour eq 'html' so... # this may be customized to include a class name or whatever other tag(s) you # want. $code_head = ''; $code_foot = ''; # the head and foot of a blockquote-style block of code. this is normally # used for any code longer than one line, or even for single lines which # deserve special attention. these blocks are designated by matching pairs of # @'s signs. # ex: # ... # @@ # public String getNastyString(int foo, int bar) { # StringBuffer fonk = new StringBuffer(""); # for (int i = foo; i < bar; i++) { # fonk = fonk.append(getSomeString(i)); # } # return fonk.toString(); # } # @@ # ... # becomes (by default): # ... #
# public String getNastyString(int foo, int bar) { # StringBuffer fonk = new StringBuffer(""); # for (int i = foo; i < bar; i++) { # fonk = fonk.append(getSomeString(i)); # } # return fonk.toString(); # } #
# ... # this may be customized to include class names or whatever other tag(s) you # want. the current rational is "the following is code, it should be treated # much like a blockquote, and is already preformatted." $block_code_head = "
"; $block_code_foot = "
"; # -------------------------------- $enabled = $auto_enable || $meta::coderpants_enable; $enabled = 0 if $meta::coderpants_disable; sub start { return 1; } sub story { my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; return 1 if (!$enabled); # block code # #$$body_ref =~ s/(\s)@@([^\s]+)@@(\s)/$1$block_code_head$2$block_code_foot$3/sg; # one whitespace character = $1 followed by # '@@' followed by # one or more whitespace characters = $2 (ignored) followed by # one or more of any character = $3 followed by # one or more whitespace characters = $4 (ignored) followed by # '@@' followed by # one whitespace character = $5 # multiline #$$body_ref =~ s/(\s)@@(\s+)(.+?)(\s+)@@(\s)/$1$block_code_head$3$block_code_foot$5/sg; # one whitespace character = $1 followed by # '@@' followed by # one or more of any character = $2 followed by # '@@' followed by # one whitespace character = $3 # multiline # # takes care of " @@whatever@@ " $$body_ref =~ s/(\s)@@(.+?)@@(\s)/$1$block_code_head$2$block_code_foot$3/sg; # inline code # # one whitespace character = $1 followed by # '@' followd by # one or more non-whitespace characters = $2 followed by # '@' followed by # one whitespace character = $3 # # takes care of " @x@ ", " @xx@ ", etc. $$body_ref =~ s/(\s)@([^\s]+)@(\s)/$1$code_head$2$code_foot$3/g; # one whitespace character = $1 followed by an # '@' followed by # one non-whitespace character = $2 followed by # one or more of any character = $3 followed by # one non-whitespace character = $4 followed by # '@' followed by # one whitespace character = $5 # # takes care of all other cases of " @[morethantwocharacters]@ " $$body_ref =~ s/(\s)@([^\s])(.+?)([^\s])@(\s)/$1$code_head$2$3$4$code_foot$5/g; return 1; } 1;