[Pmwiki-users] bold/italic/underlined/colored/tagged hotwords

J. Meijer commentgg
Thu May 27 18:00:21 CDT 2004


Another regular expressions exercise, suitable for highlighting (or
whatever) a certain set of words.
Once in your config.sys  the code below (in three separate parts) enables
the following syntax:

   [[bold:word1|word2|etc]]
   [[italic:word1|word2|etc]]
   [[underline:word1|word2|etc]]

   [[#FFF:word1|word2|etc]]
   [[#FFFFFF:word1|word2|etc]]
   [[colorname:word1|word2|etc]]

   [[<tagtext$1tagtext>:word1|word2|etc]]  f.e.
   [[<img src='images/$1.png'>:fools|wisdom]]

All variations work on lists of words seperated by '|' without spaces.
Subsequent occurrences of those words are then tagged to appear: boldfaced,
italicized, underlined, colored or HTML-tagged.

Important: these markups become effective beginning with the line they are
on. Unique feature :-)

Fresh code: Thou shall have weaknesses and bugs.

Any suggestions welcome, though responses may take a week or more, due to
long off-line periods.

-jm



# NEXT DEFINITIONS BECOME VALID AFTER THEY OCCUR IN THE TEXT
# allow hotwords [[bold:word|word|..]] [[italic:word|word|..]]
[[underline:word|word|..]]
$DoubleBrackets["/\\[\\[(?:(b)old|(i)talic|(u)nderline):(\\w+(?:\\|\\w+)*)\\
]\\]/se"]=
    'eval(\'$InlineReplacements["/\\b($4)\\b/"] = "<$1$2$3>\$1</$1$2$3>";
return "";\')';
# allow hotwords [[#color:word|word|..]]
$DoubleBrackets["/\\[\\[(#[0-9a-fA-F]{3}|#[0-9a-fA-F]{6}|aqua|black|blue|fuc
hsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white):(\\w+(?
:\\|\\w+)*)\\]\\]/se"]=
    'eval(\'$InlineReplacements["/\\b($2)\\b/"] = "<font color=$1
>\$1</font>"; return "";\')';
# allow hotwords [[<tag>$1</tag>:word|..]]
#NOTE tag is not allowed to have '(' and ')', so scripts won't run
$DoubleBrackets["/\\[\\[(&lt;[^()]*?)\\$1([^()]*?&gt;):(\\w+(?:\\|\\w+)*)\\]
\\]/se"]=
    'eval(\'$InlineReplacements["/\\b($3)\\b/"] =
html_entity_decode("$1\\\\\$1$2"); return "";\')';






More information about the pmwiki-users mailing list