summaryrefslogtreecommitdiff
path: root/includes/pear/Text/Wiki/Parse/Creole/Trim.php
blob: f10c9a2703d2765ea68e5bc438efb4a0c9bcc2f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

/**
 *
 * Trim lines in the source text and compress 3 or more newlines to
 * 2 newlines.
 *
 * @category Text
 *
 * @package Text_Wiki
 *
 * @author Paul M. Jones <pmjones@php.net>
 * @author Michele Tomaiuolo <tomamic@yahoo.it>
 *
 */

class Text_Wiki_Parse_Trim extends Text_Wiki_Parse {


    /**
     *
     * Simple parsing method.
     *
     * @access public
     *
     */

    function parse()
    {
        // trim lines
        $find = "/ *\n */";
        $replace = "\n";
        $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);

        // trim lines with only one dash or star
        $find = "/\n[\-\*]\n/";
        $replace = "\n\n";
        $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);

        // finally, compress all instances of 3 or more newlines
        // down to two newlines.
        $find = "/\n{3,}/m";
        $replace = "\n\n";
        $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
            
        // numbered lists
        $find = "/(\n[\*\#]*)([\d]+[\.\)]|[\w]\)) /s";
        $replace = "$1# ";
        $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);

        // numbers in parentesis are footnotes and references
        $find = "/\(([\d][\d]?)\)/";
        $replace = "[$1]";
        $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);

        // add hr before footnotes
        $find = "/(\n+\-\-\-\-+\n*)?(\n\[[\d]+\].*)/s";
        $replace = "\n\n----\n\n$2";
        $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);

		/*
		// wrap images in tables
        $find = "/(?<=\n\n){{([^\|}]*)\|([^}]*)}}(?=\n\n)/";
        $replace = "| {{ $1 | $2 }}\n|= $2";
        $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
		
        // wrap images in tables
        $find = "/(?<=\n\n){{([^\|}]*)}}(?=\n\n)/";
        $replace = "| {{ $1 }}";
        $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
		*/
    }

}
?>