- 论坛徽章:
- 0
|
工作量好大,不写了。 还是用XML + XSL
- <?
- class NeoFormatting{
- public $input;
- public $output;
- public function __construct(){
- }
- public function generation(){
- }
- public function trac(){
- $string = $this->input;
- $patterns[0] = '/\={1} (\w+) \={1}/';
- $patterns[1] = '/== (\w+) ==/';
- $patterns[2] = '/=== (\w+) ===/';
- $replacements[0] = '<h1>${1}</h1>';
- $replacements[1] = '<h2>${1}</h2>';
- $replacements[2] = '<h3>${1}</h3>';
- //$string = preg_replace($patterns, $replacements, $string);
- $string = preg_replace('/={7} (\w+) ={7}/', '<h7>${1}</h7>', $string);
- $string = preg_replace('/={6} (\w+) ={6}/', '<h6>${1}</h6>', $string);
- $string = preg_replace('/={5} (\w+) ={5}/', '<h5>${1}</h5>', $string);
- $string = preg_replace('/={4} (\w+) ={4}/', '<h4>${1}</h4>', $string);
- $string = preg_replace('/=== (\w+) ===/', '<h3>${1}</h3>', $string);
- $string = preg_replace('/== (\w+) ==/', '<h2>${1}</h2>', $string);
- $string = preg_replace('/= (\w+) =/', '<h1>${1}</h1>', $string);
- //$string = preg_replace('/\{\{\{(\w+)\}\}\}/', '<pre>${1}</pre>', $string);
- $string = str_replace('{{{', '<pre>', $string);
- $string = str_replace('}}}', '</pre>', $string);
- // $string = str_replace('<', '<', $string);
- // $string = str_replace('>', '>', $string);
- $string = preg_replace('/(\s(\*)\s(\w+))+/', '<ul>${1}</ul>', $string);
- $string = preg_replace('/\s(\*)\s(\w+)/', '<li>${2}</li>', $string);
- $this->output = $string;
- }
- }
- $nf = new NeoFormatting();
- $nf->input = "
- = Heading =\r\n
- == Heading ==\r\n
- === Heading ===\r\n
- ==== Heading ====\r\n
- ===== Heading =====\r\n
- ====== Heading ======\r\n
- ======= Heading =======\r\n
- \r\n
- {{{\r\n
- <?
- class hello{
- public hello(){
- }
- }
- ?>\r\n
- }}}
- \r\n
- * line 1\r\n
- * line 1\r\n
- * line 1\r\n
- * line 1\r\n
- \r\n
- ";
- $nf->trac();
- echo $nf->output;
- ?>
复制代码 |
|