Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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>
‘ &#8211; ‘, // en dash
</pre>
And add the below line after it
<pre>
‘&#160;$1’, // hack
</pre>
This assumes that all of the extra characters you are altering for “correctness” just require &#160; as a prefix.
Last edited by Manfre (2005-04-22 05:56:22)
Offline
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 &#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 &#160;:
Thanks…
Last edited by Jeremie (2005-04-22 06:40:01)
Offline
Re: Need help from a regexp guru for a Textile thing
With leading space
‘/(\s[?:$])/’, // hackWith optional leading space
‘/((?:\s)?[?:$])/’, // hackOffline
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
' :', // Hack JB pour :
' ;', // Hack JB pour ;
' !', // Hack JB pour !
' ?', // 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
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
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
</code>
</pre>
==
—————————————
Offline
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