paragraph.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Paul M. Jones <pmjones@ciaweb.net> |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: paragraph.php,v 1.2 2004/01/31 02:41:24 pmjones Exp $
  20. /**
  21. *
  22. * This class implements a Text_Wiki rule to find sections of the source
  23. * text that are paragraphs. A para is any line not starting with a token
  24. * delimiter, followed by two newlines.
  25. *
  26. * @author Paul M. Jones <pmjones@ciaweb.net>
  27. *
  28. * @package Text_Wiki
  29. *
  30. */
  31. class Text_Wiki_Rule_paragraph extends Text_Wiki_Rule {
  32. /**
  33. *
  34. * The regular expression used to find source text matching this
  35. * rule.
  36. *
  37. * @access public
  38. *
  39. * @var string
  40. *
  41. */
  42. function Text_Wiki_Rule_paragraph(&$obj, $name)
  43. {
  44. parent::Text_Wiki_Rule($obj, $name);
  45. $this->regex = "/^(?!{$this->_wiki->delim}).*?\n\n/m";
  46. }
  47. /**
  48. *
  49. * Generates a token entry for the matched text. Token options are:
  50. *
  51. * 'text' => The full matched text.
  52. *
  53. * @access public
  54. *
  55. * @param array &$matches The array of matches from parse().
  56. *
  57. * @return A delimited token number to be used as a placeholder in
  58. * the source text.
  59. *
  60. */
  61. function process(&$matches)
  62. {
  63. if (trim($matches[0]) == '') {
  64. return $matches[0];
  65. } else {
  66. $start = $this->addToken(array('type' => 'start'));
  67. $end = $this->addToken(array('type' => 'end'));
  68. return $start . trim($matches[0]) . $end;
  69. }
  70. }
  71. /**
  72. *
  73. * Renders a token into text matching the requested format.
  74. *
  75. * @access public
  76. *
  77. * @param array $options The "options" portion of the token (second
  78. * element).
  79. *
  80. * @return string The text rendered from the token options.
  81. *
  82. */
  83. function renderXhtml($options)
  84. {
  85. extract($options); //type
  86. if ($type == 'start') {
  87. return '<p>';
  88. }
  89. if ($type == 'end') {
  90. return "</p>\n\n";
  91. }
  92. }
  93. }
  94. ?>