X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/4ef96e2d9994c407f0f2f46301eb91fab6b48a37..28edab5ea9659878d6ab94428311ae21fb13c3a3:/doc/todo/color_plugin.mdwn diff --git a/doc/todo/color_plugin.mdwn b/doc/todo/color_plugin.mdwn index ec246f9d6..19fba3b35 100644 --- a/doc/todo/color_plugin.mdwn +++ b/doc/todo/color_plugin.mdwn @@ -58,6 +58,11 @@ comments are very welcome. --[[Paweł|ptecza]] >> Similar hardcoded method I've found in `img` plugin :) But only one >> argument is not named there (image path). +>>> I think I hadn't realized what you were doing there. The order +>>> for unnamed parameters can in fact be relied on. +>>> +>>> --[[Joey]] + >> Maybe I shouldn't use so simple plugin syntax? For following syntax >> I wouldn't have that problem: @@ -89,112 +94,138 @@ comments are very welcome. --[[Paweł|ptecza]] >> I don't like that too, but I didn't have better idea :) Thank you for >> the hint! I'll take a look at `toggle` plugin. - --- /dev/null 2008-07-24 09:38:19.000000000 +0200 - +++ color.pm 2008-07-25 14:43:15.000000000 +0200 - @@ -0,0 +1,75 @@ +--- + +And here is RC2 of that plugin. I've changed a plugin syntax, because the old +seems to be too enigmatic and it was hard to me to handle unnamed parameters +in not hardcoded way. I hope that my changes are acceptable for you. +Of course, I'm open for discussion or exchange of ideas :) --[[Paweł|ptecza]] + +> One question, why the 2px padding for span.color? --[[Joey]] + +>> Sorry for a long silence, but I had Internet free summer holiday :) +>> I did that, because backgrounded text without any padding looks +>> strange for me ;) You can remove it if you don't like that padding. +>> --[[Paweł|ptecza]] + +>>> Joey, will you add that plugin to Ikiwiki 2.61? :) --[[Paweł|ptecza]] + +>>>> I also had a long net-free summer holiday. :-) The [[patch]] is +>>>> ready for integration (made a few minor changes). Is this GPL 2? +>>>> --[[Joey]] + +>>>>> No problem. I guessed it, because I've not seen your commits +>>>>> at [[RecentChanges]] page in last days and I subscribe your +>>>>> [blog](http://kitenet.net/~joey/blog/entry/vacation/) :D +>>>>> It's GPL-2+ like your Ikiwiki and the most external plugins. +>>>>> --[[Paweł|ptecza]] + + --- /dev/null 2008-06-21 02:02:15.000000000 +0200 + +++ color.pm 2008-07-27 14:58:12.000000000 +0200 + @@ -0,0 +1,69 @@ +#!/usr/bin/perl +# Ikiwiki text colouring plugin - +# Paweł Tęcza + +# Paweł‚ Tęcza +package IkiWiki::Plugin::color; + +use warnings; +use strict; +use IkiWiki 2.00; + - +sub import { #{{{ + +sub import { + hook(type => "preprocess", id => "color", call => \&preprocess); - + hook(type => "sanitize", id => "color", call => \&sanitize); - +} #}}} + + hook(type => "format", id => "color", call => \&format); + +} + + + +sub preserve_style ($$$) { + + my $foreground = shift; + + my $background = shift; + + my $text = shift; + + + + $foreground = defined $foreground ? lc($foreground) : ''; + + $background = defined $background ? lc($background) : ''; + + $text = '' unless (defined $text); + - +sub preserve_style(@) { #{{{ - + my ($colors, $text) = @_; - + $colors = '' unless $colors; # foreground and background colors - + $text = '' unless $text; # text - + - + # Check colors - + my ($color1, $color2) = (); - + $colors = lc($colors); # Regexps on lower case strings are simpler - + if ($colors =~ /,/) { - + # Probably defined both foreground and background color - + ($color1, $color2) = ($colors =~ /(.*),(.*)/); - + } - + else { - + # Probably defined only foreground color - + ($color1, $color2) = ($colors, ''); - + } - + + # Validate colors. Only color name or color code are valid. - + my ($fg, $bg) = (); - + $fg = $color1 if ($color1 && - + ($color1 =~ /^[a-z]+$/ || $color1 =~ /^#[0-9a-f]{3,6}$/)); - + $bg = $color2 if ($color2 && - + ($color2 =~ /^[a-z]+$/ || $color2 =~ /^#[0-9a-f]{3,6}$/)); + + $foreground = '' unless ($foreground && + + ($foreground =~ /^[a-z]+$/ || $foreground =~ /^#[0-9a-f]{3,6}$/)); + + $background = '' unless ($background && + + ($background =~ /^[a-z]+$/ || $background =~ /^#[0-9a-f]{3,6}$/)); + + my $preserved = ''; - + if ($fg || $bg) { - + $preserved .= 'COLORS {'; - + $preserved .= 'color: '.$fg if ($fg); - + $preserved .= '; ' if ($fg && $bg); - + $preserved .= 'background-color: '.$bg if ($bg); - + $preserved .= '} SROLOC;TEXT {'.$text.'} TXET'; - + } + + $preserved .= ''; + + $preserved .= 'color: '.$foreground if ($foreground); + + $preserved .= '; ' if ($foreground && $background); + + $preserved .= 'background-color: '.$background if ($background); + + $preserved .= ''; + + $preserved .= ''.$text.''; + + return $preserved; + - +} #}}} + +} + - +sub replace_preserved_style(@) { #{{{ + +sub replace_preserved_style ($) { + my $content = shift; + - + if ($content) { - + $content =~ s/COLORS {//; - + $content =~ s/} TXET/<\/span>/; - + } + + $content =~ s!((color: ([a-z]+|\#[0-9a-f]{3,6})?)?((; )?(background-color: ([a-z]+|\#[0-9a-f]{3,6})?)?)?)!!g; + + $content =~ s!!!g; + + + + return $content; + +} + + + +sub preprocess (@) { + + my %params = @_; + - + return $content; - +} #}}} + + # Preprocess the text to expand any preprocessor directives + + # embedded inside it. + + $params{text} = IkiWiki::preprocess($params{page}, $params{destpage}, + + IkiWiki::filter($params{page}, $params{destpage}, $params{text})); + - +sub preprocess (@) { #{{{ - + return preserve_style($_[0], $_[2]); - +} #}}} + + return preserve_style($params{foreground}, $params{background}, $params{text}); + +} + - +sub sanitize (@) { #{{{ + +sub format (@) { + my %params = @_; - + - + return replace_preserved_style($params{content}) - + if (exists $params{content}) - +} #}}} + + + + $params{content} = replace_preserved_style($params{content}); + + return $params{content}; + +} + +1 - --- /dev/null 2008-07-24 09:38:19.000000000 +0200 - +++ color.mdwn 2008-07-25 14:50:19.000000000 +0200 - @@ -0,0 +1,31 @@ - +\[[!template id=plugin name=color core=0 author="[[Paweł Tęcza|ptecza]]"]] + --- /dev/null 2008-06-21 02:02:15.000000000 +0200 + +++ color.mdwn 2008-07-27 15:04:42.000000000 +0200 + @@ -0,0 +1,25 @@ + +\[[!template id=plugin name=color core=0 author="[[ptecza]]"]] + - +This plugin can be used to color a piece of text on Ikiwiki page. - +It's possible setting foreground and/or background color of the text. + +This plugin can be used to color a piece of text on a page. + +It can be used to set the foreground and/or background color of the text. + - +The plugin syntax is very simple. You only need to type name (e.g. `white`) - +or HTML code of colors (e.g. `#ffffff`) and a text you want to color. - +The colors should by separated using a comma character. + +You can use a color name (e.g. `white`) or HTML code (e.g. `#ffffff`) + +to define colors. + +Below are a few examples: + - + \[[!color white,#ff0000 "White text on red background"]] + + \[[!color foreground=white background=#ff0000 text="White text on red background"]] + - +Foreground color is defined as a word, background color is defined as HTML + +In the above example, the foreground color is defined as a word, while the background color is defined as a HTML +color code. + - + \[[!color white "White text on default color background"]] + + \[[!color foreground=white text="White text on default color background"]] + - +Foreground color is default color if only one color was typed and a comma - +character is missing. + +The background color is missing, so the text is displayed on default background. + - + \[[!color white, "White text on default color background"]] + + \[[!color background=#ff0000 text="Default color text on red background"]] + - +Background color is missing, so the text is displayed on default background. + +The foreground is missing, so the text has the default foreground color. + --- style.css-orig 2008-07-27 15:12:39.000000000 +0200 + +++ style.css 2008-07-27 15:15:06.000000000 +0200 + @@ -333,3 +333,7 @@ + background: #eee; + color: black !important; + } + - + \[[!color ,#ff0000 "Default color text on red background"]] - + - +Foreground is missing, so the text has default color. + +span.color { + + padding: 2px; + +} + +[[done]]