开发者

Is there a plugin to handle "French spacing" in WordPress?

开发者 https://www.devze.com 2023-01-06 19:32 出处:网络
I migrated from Dotclear (2.2) to WordPress (3.0) a few days ago and I have solved all my problems except one. I have not found a pluging to handle \"french spacing\".

I migrated from Dotclear (2.2) to WordPress (3.0) a few days ago and I have solved all my problems except one. I have not found a pluging to handle "french spacing".

WordPress is better than Dotclear, but since Dotclear is a French project, it manages this correctly.

By "french spacing", I mean replacing the space by an insecable space ( ) before the double punctuation (: ; ! and ?).

I tried "WP-typog开发者_开发问答raphy" but it doesn't handle this specificity of French language.


function my_super_awesome_french_spacer($content){
  $content = preg_replace( '/\s([:;!?])\s/', ' $1 ', $content );
  return $content;
}

foreach(array('the_content','the_title','comment_text') as $filter)
  add_filter($filter, 'my_super_awesome_french_spacer',9);

Drop that into your theme's functions.php file and it will enforce the French spacing for the double punctuation (as long as you formatted it that way in the visual editor) in post content, titles, and comments. If you want it to do it even if there's no space before or after, replace the RegEx with this:

'/\s?([:;!?])\s?/'

Basically, adding the question marks after the 's' tells it to replace a space w/ a non-breaking space if it's there, and to insert one if there's no space there to begin with.

0

精彩评论

暂无评论...
验证码 换一张
取 消