01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext.widgets;
04:
05: import java.util.regex.Matcher;
06: import java.util.regex.Pattern;
07:
08: public class HeaderWidget extends ParentWidget {
09: public static final String REGEXP = "^![123] [^\r\n]*(?:(?:\r\n)|\n|\r)?";
10:
11: private static final Pattern pattern = Pattern
12: .compile("!([123]) (.*)");
13:
14: private int size = 3;
15:
16: public HeaderWidget(ParentWidget parent, String text)
17: throws Exception {
18: super (parent);
19: Matcher match = pattern.matcher(text);
20: if (match.find()) {
21: size = Integer.valueOf(match.group(1)).intValue();
22: addChildWidgets(match.group(2));
23: }
24: }
25:
26: public int size() {
27: return size;
28: }
29:
30: public String render() throws Exception {
31: StringBuffer html = new StringBuffer("<h");
32: html.append(size).append(">").append(childHtml());
33: html.append("</h").append(size).append(">");
34:
35: return html.toString();
36: }
37: }
|