Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created April 23, 2012 17:25
Show Gist options
  • Save jbclements/2472484 to your computer and use it in GitHub Desktop.
Save jbclements/2472484 to your computer and use it in GitHub Desktop.
Excerpt from gitolite doc/Markdown.pl
#
# Globals:
#
# Regex to match balanced [brackets]. See Friedl's
# "Mastering Regular Expressions", 2nd Ed., pp. 328-331.
my $g_nested_brackets;
$g_nested_brackets = qr{
(?> # Atomic matching
[^\[\]]+ # Anything other than brackets
|
\[
(??{ $g_nested_brackets }) # Recursive set of nested brackets
\]
)*
}x;
# Table of hash values for escaped characters:
my %g_escape_table;
foreach my $char (split //, '\\`*_{}[]()>#+-.!') {
$g_escape_table{$char} = md5_hex($char);
}
# Global hashes, used by various utility routines
my %g_urls;
my %g_titles;
my %g_html_blocks;
# Used to track when we're inside an ordered or unordered list
# (see _ProcessListItems() for details):
my $g_list_level = 0;
#### Blosxom plug-in interface ##########################################
# Set $g_blosxom_use_meta to 1 to use Blosxom's meta plug-in to determine
# which posts Markdown should process, using a "meta-markup: markdown"
# header. If it's set to 0 (the default), Markdown will process all
# entries.
my $g_blosxom_use_meta = 0;
sub start { 1; }
sub story {
my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
if ( (! $g_blosxom_use_meta) or
(defined($meta::markup) and ($meta::markup =~ /^\s*markdown\s*$/i))
){
$$body_ref = Markdown($$body_ref);
}
1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment