forked from bentglasstube/blosxom-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoderpants-v0i1
131 lines (114 loc) · 4.13 KB
/
coderpants-v0i1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/perl
# Blosxom Plugin: coderpants
# Author(s): Eric Sherman <[email protected]
# Version: 2003-04-28 (v0.1)
# Documentation: http://enkidu.bloggedup.com/development/blosxom/coderpants/
#
# Translates @blah blah blah@ and @@blah blah blah@@ in story files into
# nicely formatted <code></code> 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 <code>template</code> activates when <code>$blosxom::flavour eq 'html'</code> so...
# this may be customized to include a class name or whatever other tag(s) you
# want.
$code_head = '<code>';
$code_foot = '</code>';
# 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):
# ...
# <pre><blockquote><code>
# 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();
# }
# </code></blockquote></pre>
# ...
# 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 = "<pre><blockquote><code>";
$block_code_foot = "</code></blockquote></pre>";
# --------------------------------
$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;