post_typo

The post_typo pipeline is used to modify text after SPIP has applied its normal typographical processes, and therefore also after the pre_typo pipeline. It is called by the corriger_typo() function in ecrire/inc/texte.php, a function which itself is called when using the propre() or typo() functions.

  1. $letexte = pipeline('post_typo', $letexte);

Example

The "Typo Guillemets" plugin replaces quotation marks " in a piece of entered text with the appropriate equivalent depending on the language code, such as using « and » for French texts. To do this, it analyses the text for typographical short-cuts that have been applied as shown below:

  1. function typo_guillemets_post_typo($texte) {
  2. // ...
  3. switch ($GLOBALS['spip_lang']) {
  4. case 'fr':
  5. $guilles="«  »"; //LRTEUIN
  6. break;
  7. // ...
  8. }
  9.  
  10. // escape any " found in the tags;
  11. // note <!--extra--> is the character chr(1), and <!--extra--> represents the tag
  12. $texte = preg_replace(',<[^>]*"[^>]*(>|$),msSe', "str_replace('\"','<!--extra-->', \"<!--extra-->\")", $texte);
  13.  
  14. // We correct any remaining quotes, which are by definition not within tags
  15. // A quote is not processed if it follows a non-space character, or
  16. // if it is followed by a word (letter, digit)
  17. $texte = preg_replace('/(^|\s)"\s?([^"]*?)\s?"(\W|$)/S', '<!--extra-->'.$guilles.'', $texte);
  18.  
  19. // and put back the quotes in any tags
  20. return str_replace("<!--extra-->", '"', $texte);
  21. }

Download

Author Mark Baber Published : Updated : 12/05/17

Translations : English, français