4 This plugin provides for CSS support in WikiPages. To add a style
5 (color, background, font, etc.) simply use the "@@" to initiate
8 @@cssparagraph ... here comes the text
9 that is formatted according to the style
10 class ".cssparagraph" of our stylesheet
12 In the above example the style is applied to the whole paragraph (every
13 piece of text, that follows the @@). But you can also assign styles to
14 just some parts of the text or even intermix and overlap multiple style
15 definitions. To do so, you must however close a begun style allocation:
17 @@parastyle ... some text following
18 ... but @@color:red; this part@@ is
20 And @@subdef1 ...here... @@more3 ... @@
21 a piece@@ of nested CSS-stuff.
23 In this example (looks a bit weird) the last two definitions are nested!
24 Note also, that you cannot only assign CSS class names to a paragraph or
25 piece of text, but also direct format it using all possible CSS
26 definitions - but beware that there cannot be any whitespace in the CSS
27 instruction that you apply using this syntax.
29 This plugin uses regular expressions, but does not slow down the
30 rendering process much more than any other plugin!
32 See also the 'markup_css_singleat' plugin, which allows to use just
33 a single @ instead of two, like with javadoc. Both can be used
34 alternative or in conjunction.
38 define("EWIKI_CSS_BLOCK", "div");
39 define("EWIKI_CSS_INLINE", "span");
40 define("EWIKI_CSS_CLASSPREP", ""); # "wiki-" for example
41 define("EWIKI_CSS_LOWER", 0); # classnames to lowercase
42 define("EWIKI_CSS_FIX", 0); # allow only correct classnames
44 $ewiki_plugins["format_source"][] = "ewiki_format_css";
48 function ewiki_format_css(&$src) {
50 #-- wikisource is splitted into paragraphs and later reconcatenated
51 # (which will collapse multiple linebreaks, and thus may break some
52 # things in <pre> and eventually others - the impact would be little!)
53 if (strpos($src, "@@") !== false) {
55 $src = explode("\n\n", $src);
57 foreach ($src as $i=>$para) {
58 if (strpos($para, "@@") !== false) {
59 ewiki_format_css_para($src[$i]);
63 $src = implode("\n\n", $src);
70 function ewiki_format_css_para(&$para) {
72 #-- opened html container elememts
75 #-- how class names may look
76 $s_defs = EWIKI_CSS_FIX
77 ? '[-\dA-Za-z]*|[^\s]+:[^\s]+' // disallow wrong class names
78 : '[^\s]*'; // allows nearly anything
80 #-- find every @@ occourence
81 while (preg_match('/^(.*?)@@('.$s_defs.')(.*)$/s', $para, $uu)) {
84 if (!strlen($uu[2])) {
87 $repl = "</" . array_pop($stack) . ">";
92 $para = $uu[1] . $repl . $uu[3];
99 #-- html container element
100 $span = (trim( $uu[1]) ? EWIKI_CSS_INLINE : EWIKI_CSS_BLOCK);
103 #-- style= or class= definition?
104 $is_class = !strpos($uu[2], ":");
106 #-- class names into lowercase?
107 if ($is_class && EWIKI_CSS_LOWER) {
108 $uu[2] = strtolower($uu[2]);
112 $para = $uu[1] . "<$span " . ($is_class ? "class" : "style")
113 . '="' . ($is_class ? EWIKI_CSS_CLASSPREP : "") . $uu[2] . '">'
119 #-- close still opened html container elements
120 while ($span = array_pop($stack)) {
124 #<off># return($para);
125 # we're now pass-by-reference