[pmwiki-users] em dash

Patrick R. Michaud pmichaud at pobox.com
Tue Sep 2 09:02:40 CDT 2008

On Mon, Sep 01, 2008 at 10:56:44PM -0400, Vince Sabio wrote:
> I need to add em-dash/en-dash capability on the wiki. Per the 
> Cookbook instructions, I added the following to config.php:
> if ($action != 'edit') {
>   # make curly quotes
>   Markup("\"",'_end',"/\"(.*?)\"/",'“$1”');
>   # make m-dash
>   Markup("---",'_end',"/---([^-])/",'—$1');
>   # make n-dash
>   Markup("--",'_end',"/--([^->])/",'–$1');
>   # curly single quote in contraction
>   Markup("a'a",'_end',"/([A-Za-z])'([A-Za-z][A-Za-z]?[^A-Za-z])/",'$1’$2');
> }
> However, using "---" does not yield an em dash. Any idea what I'm doing wrong?

You have both "---" and "--" in the "_end" section, but since "--"
is a substring of "---" that markup rule may be firing first.
(The test for [^->] doesn't really help here, because it'll
simply match the last two hyphens of --- instead of the first two.)

The solution may be to make sure that the --- rule is processed before
the -- rule:

    Markup('--',  '_end', '/--(?![->])/', '&#8211');
    Markup('---', '<--' , '/---(?!-)/',   '&#8212');

Also, performing this sort of substitution at '_end' might have
some undesirable results and grab hyphens that aren't meant to be
dashes.  In particular, it means that hyphens inside of [=...=]
and [@...@] are no longer protected.  (The same is true for the
other quote rules you've given above.)  Better might be to do things 
as part of an inline markup rule, since these are really inline

    Markup('---', 'inline', '/(?<!-)---(?!-)/', '&#8212');
    Markup('--',  '>---',   '/(?<!-)--(?!-)/',  '&#8211');


More information about the pmwiki-users mailing list