[Home]WikiPatches/TextColours

UseModWiki | WikiPatches | RecentChanges | Preferences

New enhancements, they work like italic and bold:

Patch 1

@@@ Red+bold @@@ ^^^ Green ^^^ ~~~ Blue ~~~ --- Small --- +++ Big +++ Patch:

sub CommonMarkup {
...
  if ($doLines) {
...
    s/(@*)@@@(.*?)@@@/$1<FONT COLOR="red"><B>$2<\/B><\/FONT>/g;
    s/(\^*)\^\^\^(.*?)\^\^\^/$1<FONT COLOR="green">$2<\/FONT>/g;
    s/(~*)~~~(.*?)~~~/$1<FONT COLOR="blue">$2<\/FONT>/g;
    s/(-*)---(.*?)---/$1<FONT SIZE="-1">$2<\/FONT>/g;
    s/(\+*)\+\+\+(.*?)\+\+\+/$1<FONT SIZE="+1">$2<\/FONT>/g;
## Tables:
...
  }
  return $_;
}
--HaJoGurt For red text, I decided it was more meaningful to just write <red>Red text</red>. I placed the following after the expression matching <tt/>.
    s/\<red\>(.*?)\<\/red\>/&StoreRaw('<span style="color:red">') . $1 . '<\/span>'/geis;
I don't think @@@ really means red to me. It's too cooked. But either way, you should use the <span/> tag, not <font/>. And if you do, don't forget to StoreRaw() it! That colon gets matched later for the dictionary lists, as I discovered. :( -- SunirShah

Here are all 16 colors:

  	# dco Handle colors.  
  	s/\<black\>(.*?)\<\/black\>/&StoreRaw('<span style="color:black">') . $1 . '<\/span>'/gei;
  	s/\<green\>(.*?)\<\/green\>/&StoreRaw('<span style="color:green">') . $1 . '<\/span>'/gei;
  	s/\<silver\>(.*?)\<\/silver\>/&StoreRaw('<span style="color:silver">') . $1 . '<\/span>'/gei;
  	s/\<lime\>(.*?)\<\/lime\>/&StoreRaw('<span style="color:lime">') . $1 . '<\/span>'/gei;
  	s/\<gray\>(.*?)\<\/gray\>/&StoreRaw('<span style="color:gray">') . $1 . '<\/span>'/gei;
  	s/\<olive\>(.*?)\<\/olive\>/&StoreRaw('<span style="color:olive">') . $1 . '<\/span>'/gei;
  	s/\<white\>(.*?)\<\/white\>/&StoreRaw('<span style="color:white">') . $1 . '<\/span>'/gei;
  	s/\<yellow\>(.*?)\<\/yellow\>/&StoreRaw('<span style="color:yellow">') . $1 . '<\/span>'/gei;
  	s/\<maroon\>(.*?)\<\/maroon\>/&StoreRaw('<span style="color:maroon">') . $1 . '<\/span>'/gei;
  	s/\<navy\>(.*?)\<\/navy\>/&StoreRaw('<span style="color:navy">') . $1 . '<\/span>'/gei;
  	s/\<red\>(.*?)\<\/red\>/&StoreRaw('<span style="color:red">') . $1 . '<\/span>'/gei;
  	s/\<blue\>(.*?)\<\/blue\>/&StoreRaw('<span style="color:blue">') . $1 . '<\/span>'/gei;
  	s/\<purple\>(.*?)\<\/purple\>/&StoreRaw('<span style="color:purple">') . $1 . '<\/span>'/gei;
  	s/\<teal\>(.*?)\<\/teal\>/&StoreRaw('<span style="color:teal">') . $1 . '<\/span>'/gei;
  	s/\<fuchsia\>(.*?)\<\/fuchsia\>/&StoreRaw('<span style="color:fuchsia">') . $1 . '<\/span>'/gei;
  	s/\<aqua\>(.*?)\<\/aqua\>/&StoreRaw('<span style="color:aqua">') . $1 . '<\/span>'/gei;

The above "@@@" for "red" was meant as an quick and easy way to mark something as "super-bold", e.g. for warnings etc. --HaJoGurt


I suggest a different syntax where the user specifies the colour. My suggested syntax would be

@@@colour@text@@@

which renders text in color=colour

eg

@@@red@tomato@@@ @@@green@banana@@@

would output tomato in red followed by banana in green.

I have not looked at the code but it seems to me fairly straightforward, as the code does not need to know any HTML color names, it simply passes on the colour specified by the user.

Maybe @@@red@@@tomato@@@ would be easier to code?

--RiVer


There's something wrong, something unwiky in this idea with colours. Why not using CSS (and letting the maintainer alter the colors via the stylesheet) instead? -- UrbanSheep
I think rather about the possibility to set a preferred color in ones Preferences, which would apply to all the text written as that user. This would be very valuable for closed (and semi-closed) wikis with a small number of participants. --DavidAndel
I like WikiWithCascadingStyleSheet too -- SimonD
I like the simplicity and look of this -- Tim Nelson

The following syntax was lifted from the Webmacro Wiki http://webmacro.org/WebMacroWiki DeadLink

^ -- used for color. The next word (or HTML color value) that follows the caret will be the color used:

      ^blue This text will be blue here^ 
      ^#FF0000 This text will be red here^ 

Patch 2

sub CommonMarkup {
...
  if ($doLines) {
...
     s/\^([a-zA-Z]{1,}|#[0-9A-Fa-f]{6}) (.*?)\^/<FONT COLOR="$1">$2<\/FONT>/g;

slight modification of the line to use CSS instead of FONT -- DarrinLowery?

s/\^([a-zA-Z]{1,}|#[0-9A-Fa-f]{6}) (.*?)\^/<span style="color:$1;">$2<\/span>/g;

This is BY ALL means the way you want to go. Simple & clean.

One problem with what's above: it doesn't use StoreRaw(), one symptom of which is that it breaks tables! Here's a better version:

s/\^([a-zA-Z]{1,}|#[0-9A-Fa-f]{6}) (.*?)\^/&StoreRaw('<span style="color:') . $1 . ';">' . $2 . '<\/span>'/gei;


Here's one more way to do it (TMTOWTDI), using a similar syntax to [url link text]:

Patch 3

Create a new variable for the config section so you can turn this off. :-) I called it $FontAllowed for lack of something better. Maybe I should have called it $StyleAllowed.

Put this bit of code in CommonMarkup():

  if ($FontAllowed) {
      s/{{(\S+)\s/font_size_and_color($1)/ge;
      s|}}|</span>|g;
  }

and add this subroutine to the program:

sub font_size_and_color {
    my $string = shift;
    my $span_tag = '<span style="';
    for my $attr (split /,/, $string) {
        $span_tag .= 
            ($attr =~ /(?:\d%)$/ ?  'font-size:' : 'color:') .  
            "$attr;";
    }
    $span_tag .= '">';
    return $span_tag;
}

Then you can say things like

The order of the size and color doesn't matter. Just don't put any spaces in until just before the start of the text being modified. I limited it to using percents for size to keep it simple. (My original allowed em, en, pt, px, x-large, and so on, but I decided that was overkill.) It doesn't do any error-checking on the requested color or percent, but one of the best parts of a wiki is that it's easy to fix errors, right? --DavidWall


With Domesu, I'm aiming for something like this:

   [@style *.bigred: color red, font-size 200%, font-weight bold]

Then later on in the page...

   [span.bigred]I am Ozymandias, King of Kings, Look upon my works ye mighty and despair[/span]

(div would also work, as would any block element, in fact)

It's a simple inline transform, should even be portable to usemod 1.0. I may even allow inline styles so one doesn't have to declare the style up-front. Ultimately I have a far more complex scheme in mind than simple CSS syntax sugar (imagine dynamically composing styles), but that's a different story... Anyway, how does the above syntax look? --ChuckAdams


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited September 27, 2009 10:58 am by JuanmaMP (diff)
Search: