Changeset 1219

Show
Ignore:
Timestamp:
08/11/2008 03:21:08 PM (2 years ago)
Author:
DarTar
Message:

Moving constants to top and checking if already defined, refs #503

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/formatters/wakka.php

    r1218 r1219  
    11<?php 
    22/** 
    3  * Wikka Formatting Engine 
     3 * The Wikka Formatting Engine 
    44 *  
    55 * This is the main formatting engine used by Wikka to parse wiki markup and render valid XHTML. 
     
    3434if (!defined('PATTERN_CODE')) define('PATTERN_CODE', '(.*)'); 
    3535/**#@-*/ 
    36  
    3736/** 
    3837 * Match heading tags. 
     
    6059 */ 
    6160if (!defined('PATTERN_MATCH_PAGE_FORMATOPTION')) define('PATTERN_MATCH_PAGE_FORMATOPTION', '/(^|;)page(;|$)/'); 
     61/** 
     62 * Match "<a " when it isn't preceded by "</a>" 
     63 */ 
     64if (!defined('PATTERN_OPEN_A_ALONE')) define('PATTERN_OPEN_A_ALONE', '(?<!</a>|^)<a '); 
     65/** 
     66 * Match the end of a string when the string doesn't end with </a> 
     67 */ 
     68if (!defined('PATTERN_END_OF_STRING_ALONE')) define('PATTERN_END_OF_STRING_ALONE', '(?<!</a>)$'); 
     69/** 
     70 * Match "</a>" when it is not followed by an opening link markup (<a ) 
     71 */ 
     72if (!defined('PATTERN_CLOSE_A_ALONE')) define('PATTERN_CLOSE_A_ALONE', '</a>(?!<a |$)'); 
     73/** 
     74 * Match the start of a string when the string doesn't start with "<a " 
     75 */ 
     76if (!defined('PATTERN_START_OF_STRING_ALONE')) define('PATTERN_START_OF_STRING_ALONE', '^(?!<a )'); 
    6277 
    6378// @@@  is this condition handy? would prevent generating IDs on a page fragment 
     
    127142                                        $opening_anchor = '<a class="heading" href="#'.$h_id.'">'; 
    128143                                        $closing_anchor = '</a>'; 
    129                                         /** 
    130                                          * Match "<a " when it isn't preceded by "</a>" 
    131                                          */ 
    132                                         define('PATTERN_OPEN_A_ALONE', '(?<!</a>|^)<a '); 
    133                                         /** 
    134                                          * Match the end of a string when the string doesn't end with </a> 
    135                                          */ 
    136                                         define('PATTERN_END_OF_STRING_ALONE', '(?<!</a>)$'); 
    137                                         /** 
    138                                          * Match "</a>" when it is not followed by an opening link markup (<a ) 
    139                                          */ 
    140                                         define('PATTERN_CLOSE_A_ALONE', '</a>(?!<a |$)'); 
    141                                         /** 
    142                                          * Match the start of a string when the string doesn't start with "<a " 
    143                                          */ 
    144                                         define('PATTERN_START_OF_STRING_ALONE', '^(?!<a )'); 
    145144                                        $h_heading = preg_replace('@('.PATTERN_OPEN_A_ALONE. '|'.PATTERN_END_OF_STRING_ALONE.  ')@', $closing_anchor.'\\0', $h_heading); 
    146145                                        $h_heading = preg_replace('@('.PATTERN_CLOSE_A_ALONE.'|'.PATTERN_START_OF_STRING_ALONE.')@', '\\0'.$opening_anchor, $h_heading); 
    147146 
    148147                                        // rebuild element, adding id 
    149                                         return '<'.$h_tagname.$h_attribs.' id="'.$h_id.'">'.$h_heading.'</'.$h_tagname.'>'; 
     148                                        return '<a class="heading" href="#'.$h_id.'"><'.$h_tagname.$h_attribs.' id="'.$h_id.'">'.$h_heading.'</'.$h_tagname.'></a>'; 
    150149                                } 
    151150                        }