Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-04-22 05:14:35

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Need help from a regexp guru for a Textile thing

I need some help with this… I would like to hack my Textile class to help write “correct” french. But I’m not regexp savvy at all :(

This is what I would like to have :

: become  :
? become  ?

A some others, but I could extrapolate from these. In Textile, it is done by the glyph() function around line 732.

Can anyone help ?

Offline

#2 2005-04-22 05:48:09

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

Re: Need help from a regexp guru for a Textile thing

Find line 746
<pre> ‘/\s-\s/’, // en dash
</pre>

And add the below line after it. To add more, just place the character after the $. For some special chars, you will need to escape it with a single backslash ‘\’
<pre> ‘/([?:$])/’, // hack
</pre>

Find line 761

<pre>
‘ &amp;#8211; ‘, // en dash
</pre>

And add the below line after it
<pre> ‘&amp;#160;$1’, // hack
</pre>

This assumes that all of the extra characters you are altering for “correctness” just require &amp;#160; as a prefix.

Last edited by Manfre (2005-04-22 05:56:22)

Offline

#3 2005-04-22 06:37:24

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: Need help from a regexp guru for a Textile thing

Sorry Manfre, my post wasn’t clear. Before each “glyph” I want to transform, I have a regular space.

Basically, in French, all double sign punctuation (:;?!) are preceded by a non-breaking space.

So what I would like is to transform SPACE: (where SPACE is a regular space) into &amp;#160;:

I have another question, if I need to take that road someday… it’s the same mechanism, but this time without caring if the glyph is preceded by a space or not.
That mean, SPACE: (with SPACE as a space) or : are both transformed into &amp;#160;:

Thanks…

Last edited by Jeremie (2005-04-22 06:40:01)

Offline

#4 2005-04-22 14:53:51

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

Re: Need help from a regexp guru for a Textile thing

With leading space

‘/(\s[?:$])/’, // hack

With optional leading space

‘/((?:\s)?[?:$])/’, // hack

Offline

#5 2005-04-22 21:39:22

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: Need help from a regexp guru for a Textile thing

Thanks a lot Manfre !

Just one thing, I have this rule for finding the ? glyph (with a regular space before it):
'/(\s[?\?$])/',

And it doesn’t work. It came back as the : rule. These are the rules :

'/(\s[?:$])/', // Hack JB pour :
'/(\s[?\;$])/', // Hack JB pour ;
'/(\s[?\!$])/', // Hack JB pour !
'/(\s[?\?$])/', // Hack JB pour ?

and

'&#160;:', // Hack JB pour :
'&#160;;', // Hack JB pour ;
'&#160;&#033;', // Hack JB pour !
'&#160;&#063;', // Hack JB pour ? (I used an entity to be sure there was not another regexp somewhere messing with it)

So, maybe I don’t escape correctly the ?, or maybe the glyphs() function is done before/after something else that interfere with it. I tried to track it done, but… :(

Offline

#6 2005-04-22 21:42:58

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: Need help from a regexp guru for a Textile thing

Ok more : even without the last rule, every string SPACE? is transformed into the first rule’s rulst (#160;:).

Offline

#7 2005-04-24 06:29:57

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

Re: Need help from a regexp guru for a Textile thing

There is some confusion with how you entered the regex strings.

Here is the regex from mine. the first one for each array will do all of the replacements for you. This requires a space before each one.

—————————————
==<pre>
<code> $glyph_search = array( ‘/\s([?:;!$])/’, ‘/([^\s[{(>_*])?\’(?(1)|(?=\s|s\b|’.$pnc.’))/’, // single closing ‘/\’/’, // single opening ‘/([^\s[{(>_*])?”(?(1)|(?=\s|’.$pnc.’))/’, // double closing ‘/”/’, // double opening ‘/\b( )?\.{3}/’, // ellipsis ‘/\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/’, // 3+ uppercase acronym ‘/\s?—\s?/’, // em dash ‘/\s-\s/’, // en dash ‘/(\d+) ?x ?(\d+)/’, // dimension sign ‘/\b ?[([]TM[])]/i’, // trademark ‘/\b ?[([]R[])]/i’, // registered ‘/\b ?[([]C[])]/i’); // copyright

$glyph_replace = array( ‘&#160;$1’, ‘$1&#8217;$2’, // single closing ‘&#8216;’, // single opening ‘$1&#8221;’, // double closing ‘&#8220;’, // double opening ‘$1&#8230;’, // ellipsis ‘<acronym title=”$2”>$1</acronym>’, // 3+ uppercase acronym ‘&#8212;’, // em dash ‘ &#8211; ‘, // en dash ‘$1&#215;$2’, // dimension sign ‘&#8482;’, // trademark ‘&#174;’, // registered ‘&#169;’); // copyright

</code>
</pre>
==
—————————————

Offline

#8 2005-04-24 06:45:56

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: Need help from a regexp guru for a Textile thing

Indeed I was confuse. Thanks a lot Manfre, that work like a charm.

Offline

Board footer

Powered by FluxBB