]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/transform.php
Fix bugs introduced by new OOification of HTML generation.
[SourceForge/phpwiki.git] / lib / transform.php
1 <?php rcs_id('$Id: transform.php,v 1.37 2002-01-26 03:30:23 dairiki Exp $');
2 require_once('lib/WikiPlugin.php');
3 require_once('lib/HtmlElement.php');
4
5 define('WT_SIMPLE_MARKUP', 0);
6 define('WT_TOKENIZER', 1);
7 define('WT_MODE_MARKUP', 2);
8
9 define("ZERO_LEVEL", 0);
10 define("NESTED_LEVEL", 1);
11
12 class WikiTransform
13 {
14    // public variables (only meaningful during do_transform)
15    var $linenumber;     // current linenumber
16    var $replacements;   // storage for tokenized strings of current line
17    var $user_data;      // can be used by the transformer functions
18                         // to store miscellaneous data.
19    
20    // private variables
21    var $content;        // wiki markup, array of lines
22    var $mode_set;       // stores if a HTML mode for this line has been set
23    var $trfrm_func;     // array of registered functions
24    var $stack;          // stack for SetHTMLMode (keeping track of open tags)
25
26    /** init function */
27    function WikiTransform()
28    {
29       $this->trfrm_func = array();
30       $this->stack = new Stack;
31    }
32
33    /**
34     * Register transformation functions
35     *
36     * This should be done *before* calling do_transform
37     *
38     * @param $type enum  <dl>
39     * <dt>WT_MODE_MARKUP</dt>
40     * <dd>If one WT_MODE_MARKUP really sets the html mode, then
41     *     all successive WT_MODE_MARKUP functions are skipped.</dd>
42     * <dt>WT_TOKENIZER</dt>
43     * <dd> The transformer function is called once for each match
44     *      of the $regexp in the line.  The matched values are tokenized
45     *      to protect them from further transformation.</dd>
46     *
47     * @param $function string  Function name
48     * @param $regexp string  Required for WT_TOKENIZER functions.
49     * Optional for others. If given, the transformer function will only be
50     * called if the line matches the $regexp.
51     */
52    function register($type, $function, $regexp = false)
53    {
54       $this->trfrm_func[] = array ($type, $function, $regexp);
55    }
56
57    /**
58     * Sets current mode like list, preformatted text, plain text
59     *
60     * Takes care of closing (open) tags
61     *
62     * This is a helper function used to keep track of what HTML
63     * block-level element we are currently processing.
64     * Block-level elements are things like paragraphs "<p>",
65     * pre-formatted text "<pre>", and the various list elements:
66     * "<ul>", "<ol>" and "<dl>".  Now, SetHTMLMode is also used to
67     * keep track of "<li>" and "<dd>" elements. Note that some of these elements
68     * can be nested, while others can not.  (In particular, according to
69     * the HTML 4.01 specification,  a paragraph "<p>" element is not
70     * allowed to contain any other block-level elements.  Also <pre>,
71     * <li>,  <dt>, <dd>, <h1> ... have this same restriction.)
72     *
73     * SetHTMLMode generates whatever HTML is necessary to get us into
74     * the requested element type at the requested nesting level.
75     *
76     * @param $tag string Type of HTML element to open.
77     *
78     * If $tag is an array, $tag[0] gives the element type,
79     * and $tag[1] should be a hash containing attribute-value
80     * pairs for the element.
81     *
82     * If $tag is the empty string, all open elements (down to the
83     * level requested by $level) are closed.  Use
84     * SetHTMLMode('',0) to close all open block-level elements.
85     *
86     * @param $level string  Rrequested nesting level for current element.
87     * The nesting level for top level block is one (which is
88     * the default).
89     * Nesting is arbitrary limited to 20 levels.
90     *
91     * @return string Returns the HTML markup to open the specified element.
92     */
93    function SetHTMLMode($tag, $level = 1)
94    {
95       if (is_array($tag))
96          $el = new HtmlElement($tag[0], $tag[1]);
97       else
98          $el = new HtmlElement($tag);
99
100       $this->mode_set = 1;      // in order to prevent other mode markup
101                                 // to be executed
102       $retvar = '';
103          
104       if ($level > 20) {
105          // arbitrarily limit tag nesting
106           global $request;
107           $request->finish(_("Lists nested too deep in SetHTMLOutputMode"));
108       }
109       
110       if ($level <= $this->stack->cnt()) {
111          // $tag has fewer nestings (old: tabs) than stack,
112          // reduce stack to that tab count
113          while ($this->stack->cnt() > $level) {
114             $closetag = $this->stack->pop();
115             assert('$closetag != false');
116             $retvar .= "</$closetag>\n";
117          }
118
119          // if list type isn't the same,
120          // back up one more and push new tag
121          if ($tag && $tag != $this->stack->top()) {
122             $closetag = $this->stack->pop();
123             $retvar .= "</$closetag>" . $el->startTag() . "\n";
124             $this->stack->push($tag);
125          }
126    
127       }
128       else {// $level > $this->stack->cnt()
129          // Test for and close top level elements which are not allowed to contain
130          // other block-level elements.
131          if ($this->stack->cnt() == 1 and
132              preg_match('/^(p|pre|h\d)$/i', $this->stack->top()))
133          {
134             $closetag = $this->stack->pop();
135             $retvar .= "</$closetag>";
136          }
137                
138          // we add the diff to the stack
139          // stack might be zero
140          if ($this->stack->cnt() < $level) {
141             while ($this->stack->cnt() < $level - 1) {
142                // This is a bit of a hack:
143                //
144                // We're not nested deep enough, and have to make up some kind of block
145                // element to nest within.
146                //
147                // Currently, this can only happen for nested list element
148                // (either <ul> <ol> or <dl>).  What we used to do here is
149                // to open extra lists of whatever type was requested.
150                // This would result in invalid HTML, since and list is
151                // not allowed to contain another list without first containing
152                // a list item.  ("<ul><ul><li>Item</ul></ul>" is invalid.)
153                //
154                // So now, when we need extra list elements, we use a <dl>, and
155                // open it with an empty <dd>.
156                $stuff =  $this->stack->cnt() % 2 == 0 ? 'dl' : 'dd';
157                $retvar .= "<$stuff>";
158                $this->stack->push($stuff);
159             }
160
161             $retvar .= $el->startTag() . "\n";
162             $this->stack->push($tag);
163          }
164       }
165       
166       return $this->rawtoken($retvar);
167    }
168
169    /**
170     * Start new list item element.
171     *
172     * This closes any currently open list items at the specified level or deeper,
173     * then opens a new list item element.
174     *
175     * @param $list_type string  Type of list element to open.  This should
176     * be one of 'dl', 'ol', or 'ul'.
177     *
178     * @param $level integer  Nesting depth for list item.  Should be a positive integer.
179     *
180     * @param $defn_term string  Definition term.  Specifies the contents for the
181     * &lt;dt&gt; element.  Only used if $list_type is 'dl'.
182     *
183     * @return string HTML
184     */
185    function ListItem($list_type, $level, $defn_term = '')
186    {
187        $level = min($level, 10);
188        
189        $retval = $this->SetHTMLMode($list_type, 2 * $level - 1);
190        if ($list_type == 'dl') {
191            $retval .= AsXML(HTML::dt(HTML::raw($defn_term)));
192            $retval .= $this->SetHTMLMode('dd', 2 * $level);
193        }
194        else {
195            $retval .= $this->SetHTMLMode('li', 2 * $level);
196        }
197        return $retval;
198    }
199
200
201    /** Work horse and main loop.
202     *
203     * This function does the transform from wiki markup to HTML.
204     *
205     * Contains main-loop and calls transformer functions.
206     *
207     * @param $html string  HTML header (if needed, otherwise '')
208     * (This string is prepended to the return value.)
209     *
210     * @param $content array  Wiki markup as array of lines
211     *
212     * @return string HTML
213     */
214    function do_transform($html, $content)
215    {
216       global $FieldSeparator;
217
218       $this->content = $content;
219       $this->replacements = array();
220       $this->user_data = array();
221       
222       // Loop over all lines of the page and apply transformation rules
223       $numlines = count($this->content);
224       for ($lnum = 0; $lnum < $numlines; $lnum++)
225       {
226          
227          $this->linenumber = $lnum;
228          $line = $this->content[$lnum];
229          
230          // blank lines clear the current mode (to force new paragraph)
231          if (!strlen($line) || $line == "\r") {
232             $html .= $this->SetHTMLMode('', 0);
233             continue;
234          }
235
236          $this->mode_set = 0;
237
238          // main loop applying all registered functions
239          // tokenizers, markup, html mode, ...
240          // functions are executed in order of registering
241          foreach ($this->trfrm_func as $trfrm) {
242             list($flags, $func, $regexp) = $trfrm;
243
244             // if HTMLmode is already set then skip all following
245             // WT_MODE_MARKUP functions
246             if ($this->mode_set && ($flags & WT_MODE_MARKUP) != 0) 
247                continue;
248
249             if (!empty($regexp) && !preg_match("/$regexp/", $line))
250                continue;
251
252             // call registered function
253             if (($flags & WT_TOKENIZER) != 0)
254                $line = $this->tokenize($line, $regexp, $func);
255             else
256                $line = $func($line, $this);
257          }
258     
259          $html .= $line . "\n";
260       }
261       // close all tags
262       $html .= $this->SetHTMLMode('', 0);
263       
264       return new RawXml($this->untokenize($html));
265    }
266    // end do_transfrom()
267
268    // Register a new token.
269    function rawtoken($repl) {
270       global $FieldSeparator;
271       $tok = $FieldSeparator . sizeof($this->replacements) . $FieldSeparator;
272       $this->replacements[] = $repl;
273       return $tok;
274    }
275
276    // Register a new token.
277    function token($repl) {
278       return $this->rawtoken(AsXML($repl));
279    }
280    
281    // helper function which does actual tokenizing
282    function tokenize($str, $pattern, $func) {
283       // Find any strings in $str that match $pattern and
284       // store them in $orig, replacing them with tokens
285       // starting at number $ntokens - returns tokenized string
286       $new = '';      
287       while (preg_match("/^(.*?)($pattern)/", $str, $matches)) {
288          $str = substr($str, strlen($matches[0]));
289          $new .= $matches[1] . $this->token($func($matches[2], $this));
290       }
291       return $new . $str;
292    }
293
294    function untokenize($line) {
295       global $FieldSeparator;
296       
297       $chunks = explode ($FieldSeparator, "$line ");
298       $line = $chunks[0];
299       for ($i = 1; $i < count($chunks); $i += 2)
300       {
301          $tok = $chunks[$i];
302          $line .= $this->replacements[$tok] . $chunks[$i + 1];
303       }
304       return $line;
305    }
306 }
307 // end class WikiTransform
308
309
310 //////////////////////////////////////////////////////////
311
312 class WikiPageTransform
313 extends WikiTransform {
314     function WikiPageTransform() {
315         global $WikiNameRegexp, $AllowedProtocols, $InterWikiLinkRegexp;
316
317         $this->WikiTransform();
318
319         // register functions
320         // functions are applied in order of registering
321
322         $this->register(WT_SIMPLE_MARKUP, 'wtm_plugin_link');
323         $this->register(WT_MODE_MARKUP, 'wtm_plugin');
324  
325         $this->register(WT_TOKENIZER, 'wtt_doublebrackets', '\[\[');
326         $this->register(WT_TOKENIZER, 'wtt_footnotes', '^\[\d+\]');
327         $this->register(WT_TOKENIZER, 'wtt_footnoterefs', '\[\d+\]');
328         $this->register(WT_TOKENIZER, 'wtt_bracketlinks', '\[.+?\]');
329         $this->register(WT_TOKENIZER, 'wtt_urls',
330                         "!?\b($AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]");
331
332         if (function_exists('wtt_interwikilinks')) {
333             $this->register(WT_TOKENIZER, 'wtt_interwikilinks',
334                             pcre_fix_posix_classes("!?(?<![[:alnum:]])") .
335                             "$InterWikiLinkRegexp:[^\\s.,;?()]+");
336         }
337         $this->register(WT_TOKENIZER, 'wtt_bumpylinks', "!?$WikiNameRegexp");
338
339         if (function_exists('wtm_table')) {
340             $this->register(WT_MODE_MARKUP, 'wtm_table', '^\|');
341         }
342         $this->register(WT_SIMPLE_MARKUP, 'wtm_htmlchars');
343         $this->register(WT_SIMPLE_MARKUP, 'wtm_linebreak');
344         $this->register(WT_SIMPLE_MARKUP, 'wtm_bold_italics');
345         
346         $this->register(WT_MODE_MARKUP, 'wtm_list_ul');
347         $this->register(WT_MODE_MARKUP, 'wtm_list_ol');
348         $this->register(WT_MODE_MARKUP, 'wtm_list_dl');
349         $this->register(WT_MODE_MARKUP, 'wtm_preformatted');
350         $this->register(WT_MODE_MARKUP, 'wtm_headings');
351         $this->register(WT_MODE_MARKUP, 'wtm_hr');
352         $this->register(WT_MODE_MARKUP, 'wtm_paragraph');
353     }
354 };
355
356 function do_transform ($lines, $class = 'WikiPageTransform') {
357     if (is_string($lines))
358         $lines = preg_split('/[ \t\r]*\n/', trim($lines));
359
360     $trfm = new $class;
361     return $trfm->do_transform('', $lines);
362 }
363
364 class LinkTransform
365 extends WikiTransform {
366     function LinkTransform() {
367         global $WikiNameRegexp, $AllowedProtocols, $InterWikiLinkRegexp;
368
369         $this->WikiTransform();
370
371         // register functions
372         // functions are applied in order of registering
373
374         $this->register(WT_TOKENIZER, 'wtt_doublebrackets', '\[\[');
375         $this->register(WT_TOKENIZER, 'wtt_quotetoken', '\[\d+\]');
376         $this->register(WT_TOKENIZER, 'wtt_bracketlinks', '\[.+?\]');
377         $this->register(WT_TOKENIZER, 'wtt_urls',
378                         "!?\b($AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]");
379
380         if (function_exists('wtt_interwikilinks')) {
381             $this->register(WT_TOKENIZER, 'wtt_interwikilinks',
382                             pcre_fix_posix_classes("!?(?<![[:alnum:]])") .
383                             "$InterWikiLinkRegexp:[^\\s.,;?()]+");
384         }
385         $this->register(WT_TOKENIZER, 'wtt_bumpylinks', "!?$WikiNameRegexp");
386         $this->register(WT_SIMPLE_MARKUP, 'wtm_htmlchars');
387     }
388 };
389
390 /*
391 Requirements for functions registered to WikiTransform:
392
393 Signature:  function wtm_xxxx($line, &$transform)
394
395 $line ... current line containing wiki markup
396         (Note: it may already contain HTML from other transform functions)
397 &$transform ... WikiTransform object -- public variables of this
398         object and their use see above.
399
400 Functions have to return $line (doesn't matter if modified or not)
401 All conversion should take place inside $line.
402
403 Tokenizer functions should use $transform->replacements to store
404 the replacement strings. Also, they have to keep track of
405 $transform->tokencounter. See functions below. Back substitution
406 of tokenized strings is done by do_transform().
407 */
408
409
410
411    //////////////////////////////////////////////////////////
412    // Tokenizer functions
413
414
415 function  wtt_doublebrackets($match, &$trfrm)
416 {
417    return '[';
418 }
419
420 function wtt_footnotes($match, &$trfrm)
421 {
422    // FIXME: should this set HTML mode?
423    $ftnt = trim(substr($match,1,-1)) + 0;
424    $fntext = "[$ftnt]";
425    $html[] = HTML::br();
426    
427    $fnlist = $trfrm->user_data['footnotes'][$ftnt];
428    if (!is_array($fnlist)) {
429        $html[] = $fntext;
430    }
431    else {
432        $trfrm->user_data['footnotes'][$ftnt] = 'footnote_seen';
433        
434        while (list($k, $anchor) = each($fnlist)) {
435            $html[] = HTML::a(array("name" => "footnote-$ftnt",
436                                    "href" => "#$anchor",
437                                    "class" => "footnote-rev"),
438                              $fntext);
439            $fntext = '+';
440        }
441    }
442    return $html;
443 }
444
445 function wtt_footnoterefs($match, &$trfrm)
446 {
447    $ftnt = trim(substr($match,1,-1)) + 0;
448
449    $footnote_definition_seen = false;
450
451    if (empty($trfrm->user_data['footnotes']))
452       $trfrm->user_data['footnotes'] = array();
453    if (empty($trfrm->user_data['footnotes'][$ftnt]))
454       $trfrm->user_data['footnotes'][$ftnt] = array();
455    else if (!is_array($trfrm->user_data['footnotes'][$ftnt]))
456       $footnote_definition_seen = true;
457    
458
459    $link = HTML::a(array('href' => "#footnote-$ftnt"), "[$ftnt]");
460    if (!$footnote_definition_seen) {
461        $name = "footrev-$ftnt-" . count($trfrm->user_data['footnotes'][$ftnt]);
462        $link->setAttr('name', $name);
463        $trfrm->user_data['footnotes'][$ftnt][] = $name;
464    }
465    return HTML::sup(array('class' => 'footnote'), $link);
466 }
467
468 function wtt_bracketlinks($match, &$trfrm)
469 {
470     
471     if (preg_match('/^\[\s*\]$/', $match))
472         return $match;
473
474     $link = LinkBracketLink($match);
475
476     if ($link->isInlineElement())
477         return $link;
478
479     // FIXME: BIG HACK:
480     return new RawXml("</p>" . $link->asXML() . "<p>");
481 }
482
483
484 // replace all URL's with tokens, so we don't confuse them
485 // with Wiki words later. Wiki words in URL's break things.
486 // URLs preceeded by a '!' are not linked
487 function wtt_urls($match, &$trfrm) {
488     return $match[0] == "!"
489         ? substr($match,1)
490         : LinkURL($match);
491 }
492
493 // Link Wiki words (BumpyText)
494 // Wikiwords preceeded by a '!' are not linked
495 function wtt_bumpylinks($match, &$trfrm) {
496     return $match[0] == "!" ? substr($match,1) : LinkWikiWord($match);
497 }
498
499
500 // Just quote the token.
501 function wtt_quotetoken($match, &$trfrm) {
502     return $match;
503 }
504
505     
506      
507 // end of tokenizer functions
508 //////////////////////////////////////////////////////////
509
510
511 //////////////////////////////////////////////////////////
512 // basic simple markup functions
513
514 // escape HTML metachars
515 function wtm_htmlchars($line, &$transformer) {
516     return XmlElement::_quote($line);
517 }
518
519 // %%% are linebreaks
520 function wtm_linebreak($line, &$transformer) {
521     return str_replace('%%%', '<br />', $line);
522 }
523
524    // bold and italics
525    function wtm_bold_italics($line, &$transformer) {
526       $line = preg_replace('|(__)(.*?)(__)|', '<strong>\2</strong>', $line);
527       $line = preg_replace("|('')(.*?)('')|", '<em>\2</em>', $line);
528       return $line;
529    }
530
531
532
533    //////////////////////////////////////////////////////////
534    // some tokens to be replaced by (dynamic) content
535
536 // FIXME: some plugins are in-line (maybe?) and some are block level.
537 // Here we treat them all as inline, which will probably
538 // generate some minorly invalid HTML in some cases.
539 //
540 function wtm_plugin_link($line, &$transformer) {
541     // FIXME: is this good syntax?
542     global $request;      // FIXME: make these non-global?
543     
544     if (preg_match('/^(.*?)(<\?plugin-link\s+.*?\?>)(.*)$/', $line, $m)) {
545         list(, $prematch, $plugin_pi, $postmatch) = $m;
546         $loader = new WikiPluginLoader;
547         $html = $loader->expandPI($plugin_pi, $request);
548         $line = $prematch . $transformer->token($html) . $postmatch;
549     }
550     return $line;
551 }
552
553 function wtm_plugin($line, &$transformer) {
554     // FIXME: is this good syntax?
555     global $request;      // FIXME: make these non-global?
556     
557     if (preg_match('/^<\?plugin(-form)?\s.*\?>\s*$/', $line)) {
558         $loader = new WikiPluginLoader;
559         $html = $loader->expandPI($line, $request);
560         $line = $transformer->SetHTMLMode('', 0) . $transformer->token($html);
561     }
562     return $line;
563 }
564
565
566    //////////////////////////////////////////////////////////
567    // mode markup functions
568
569
570    // tabless markup for unordered, ordered, and dictionary lists
571    // ul/ol list types can be mixed, so we only look at the last
572    // character. Changes e.g. from "**#*" to "###*" go unnoticed.
573    // and wouldn't make a difference to the HTML layout anyway.
574
575    // unordered lists <UL>: "*"
576    // has to be registereed before list OL
577    function wtm_list_ul($line, &$trfrm) {
578       if (preg_match("/^([#*;]*\*)[^#]/", $line, $matches)) {
579          $numtabs = strlen($matches[1]);
580          $line = preg_replace("/^([#*]*\*)/", '', $line);
581          $line = $trfrm->ListItem('ul', $numtabs) . $line;
582       }
583       return $line;
584    }
585
586    // ordered lists <OL>: "#"
587    function wtm_list_ol($line, &$trfrm) {
588       if (preg_match("/^([#*;]*\#)/", $line, $matches)) {
589          $numtabs = strlen($matches[1]);
590          $line = preg_replace("/^([#*]*\#)/", "", $line);
591          $line = $trfrm->ListItem('ol', $numtabs) . $line;
592       }
593       return $line;
594    }
595
596
597    // definition lists <DL>: ";text:text"
598    function wtm_list_dl($line, &$trfrm) {
599       if (preg_match("/^([#*;]*;)(.*?):(.*$)/", $line, $matches)) {
600          $numtabs = strlen($matches[1]);
601          $line = $trfrm->ListItem('dl', $numtabs, $matches[2]) . $matches[3];
602       }
603       return $line;
604    }
605
606    // mode: preformatted text, i.e. <pre>
607    function wtm_preformatted($line, &$trfrm) {
608       if (preg_match("/^\s+/", $line)) {
609          $line = $trfrm->SetHTMLMode('pre') . $line;
610       }
611       return $line;
612    }
613
614    // mode: headings, i.e. <h1>, <h2>, <h3>
615    // lines starting with !,!!,!!! are headings
616    // Patch from steph/tara <tellme@climbtothestars.org>:
617    //    use <h2>, <h3>, <h4> since <h1> is page title.
618    function wtm_headings($line, &$trfrm) {
619       if (preg_match("/^(!{1,3})[^!]/", $line, $whichheading)) {
620          if($whichheading[1] == '!') $heading = 'h4';
621          elseif($whichheading[1] == '!!') $heading = 'h3';
622          elseif($whichheading[1] == '!!!') $heading = 'h2';
623          $line = preg_replace("/^!+/", '', $line);
624          $line = $trfrm->SetHTMLMode($heading) . $line;
625       }
626       return $line;
627    }
628
629 // markup for tables
630 function wtm_table($line, &$trfrm)
631 {
632    $row = '';
633    while (preg_match('/^(\|+)(v*)([<>^]?)([^|]*)/', $line, $m))
634    {
635       $line = substr($line, strlen($m[0]));
636
637       $td = HTML::td();
638       
639       if (strlen($m[1]) > 1)
640          $td->setAttr('colspan', strlen($m[1]));
641       if (strlen($m[2]) > 0)
642          $td->setAttr('rowspan', strlen($m[2]) + 1);
643       
644       if ($m[3] == '^')
645          $td->setAttr('align', 'center');
646       else if ($m[3] == '>')
647          $td->setAttr('align', 'right');
648       else
649          $td->setAttr('align', 'left');
650
651       // FIXME: this is a hack: can't tokenize whole <td></td> since we
652       // haven't marked up italics, etc... yet
653       $row .= $trfrm->rawtoken($td->startTag() . "&nbsp;");
654       $row .= trim($m[4]);
655       $row .= $trfrm->rawtoken("&nbsp;" . $td->endTag());
656    }
657    assert(empty($line));
658    $row = $trfrm->rawtoken("<tr>") . $row . $trfrm->rawtoken("</tr>");
659    
660    return $trfrm->SetHTMLMode(array('table',
661                                     array('cellpadding' => 1,
662                                           'cellspacing' => 1,
663                                           'border' => 1))) .
664        $row;
665 }
666
667    // four or more dashes to <hr>
668    // Note this is of type WT_MODE_MARKUP becuase <hr>'s aren't
669    // allowed within <p>'s. (e.g. "<p><hr></p>" is not valid HTML.)
670    function wtm_hr($line, &$trfrm) {
671       if (preg_match('/^-{4,}(.*)$/', $line, $m)) {
672          $line = $trfrm->SetHTMLMode('', 0) . '<hr />';
673          if ($m[1])
674             $line .= $trfrm->SetHTMLMode('p') . $m[1];
675       }
676       return $line;
677    }
678
679    // default mode: simple text paragraph
680    function wtm_paragraph($line, &$trfrm) {
681       return $trfrm->SetHTMLMode('p') . $line;
682    }
683
684 // (c-file-style: "gnu")
685 // Local Variables:
686 // mode: php
687 // tab-width: 8
688 // c-basic-offset: 4
689 // c-hanging-comment-ender-p: nil
690 // indent-tabs-mode: nil
691 // End:   
692 ?>