strong.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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: strong.php,v 1.2 2004/01/31 15:52:08 pmjones Exp $
  20. /**
  21. *
  22. * This class implements a Text_Wiki_Rule to find source text marked for
  23. * strong emphasis (bold) as defined by text surrounded by three
  24. * single-quotes. On parsing, the text itself is left in place, but the
  25. * starting and ending instances of three single-quotes are replaced with
  26. * tokens.
  27. *
  28. * @author Paul M. Jones <pmjones@ciaweb.net>
  29. *
  30. * @package Text_Wiki
  31. *
  32. */
  33. class Text_Wiki_Rule_strong extends Text_Wiki_Rule {
  34. /**
  35. *
  36. * The regular expression used to parse the source text and find
  37. * matches conforming to this rule. Used by the parse() method.
  38. *
  39. * @access public
  40. *
  41. * @var string
  42. *
  43. * @see parse()
  44. *
  45. */
  46. var $regex = "/\*\*(()|.*)\*\*/U";
  47. /**
  48. *
  49. * Generates a replacement for the matched text. Token options are:
  50. *
  51. * 'type' => ['start'|'end'] The starting or ending point of the
  52. * emphasized text. The text itself is left in the source.
  53. *
  54. * @access public
  55. *
  56. * @param array &$matches The array of matches from parse().
  57. *
  58. * @return A pair of delimited tokens to be used as a placeholder in
  59. * the source text surrounding the text to be emphasized.
  60. *
  61. */
  62. function process(&$matches)
  63. {
  64. $start = $this->addToken(array('type' => 'start'));
  65. $end = $this->addToken(array('type' => 'end'));
  66. return $start . $matches[1] . $end;
  67. }
  68. /**
  69. *
  70. * Renders a token into text matching the requested format.
  71. *
  72. * @access public
  73. *
  74. * @param array $options The "options" portion of the token (second
  75. * element).
  76. *
  77. * @return string The text rendered from the token options.
  78. *
  79. */
  80. function renderXhtml($options)
  81. {
  82. if ($options['type'] == 'start') {
  83. return '<strong>';
  84. }
  85. if ($options['type'] == 'end') {
  86. return '</strong>';
  87. }
  88. }
  89. }
  90. ?>