Changeset 1695 in subversion


Ignore:
Timestamp:
Aug 29, 2008 4:40:21 AM (5 years ago)
Author:
alec
Message:
  • Added PRE handling in html2text class (#1484740)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/lib/html2text.php

    r1631 r1695  
    3232*************************************************************************/ 
    3333 
     34/* 2008/08/29: Added PRE handling by A.L.E.C <alec@alec.pl> */ 
    3435 
    3536/** 
     
    200201 
    201202    /** 
     203     *  List of preg* regular expression patterns to search for in PRE body, 
     204     *  used in conjunction with $pre_replace. 
     205     * 
     206     *  @var array $pre_search 
     207     *  @access public 
     208     *  @see $pre_replace 
     209     */ 
     210    $pre_search = array( 
     211        "/\n/", 
     212        "/\t/", 
     213        '/ /', 
     214        '/<pre[^>]*>/', 
     215        '/<\/pre>/' 
     216    ); 
     217 
     218    /** 
     219     *  List of pattern replacements corresponding to patterns searched for PRE body. 
     220     * 
     221     *  @var array $pre_replace 
     222     *  @access public 
     223     *  @see $pre_search 
     224     */ 
     225    $pre_replace = array( 
     226        '<br>', 
     227        '&nbsp;&nbsp;&nbsp;&nbsp;', 
     228        '&nbsp;', 
     229        '', 
     230        '' 
     231    ); 
     232 
     233    /** 
    202234     *  Contains a list of HTML tags to allow in the resulting text. 
    203235     * 
     
    376408        $text = trim(stripslashes($this->html)); 
    377409 
     410        // Convert <PRE> 
     411        $this->_convert_pre($text); 
     412 
    378413        // Run our defined search-and-replace 
    379414        $text = preg_replace($this->search, $this->replace, $text); 
     
    445480      return $display . ' [' . ($index+1) . ']'; 
    446481      } 
     482 
     483    /** 
     484     *  Helper function for PRE body conversion. 
     485     * 
     486     *  @param string HTML content 
     487     *  @access private 
     488    */ 
     489    function _convert_pre(&$text) 
     490      { 
     491      while(preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) 
     492        { 
     493          $result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]); 
     494          $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text); 
     495        } 
     496      } 
    447497} 
    448498 
Note: See TracChangeset for help on using the changeset viewer.