package net.hillsdon.reviki.wiki.renderer.creole.ast;

import net.hillsdon.fij.text.Escape;

/**
 * Abstract class for AST nodes which just contain text.
 *
 * @author msw
 */
public abstract class TextNode extends ASTNode {
  private final String _contents;

  private final boolean _escape;

  public TextNode(final String contents, final boolean escape) {
    _contents = contents;
    _escape = escape;
  }

  @Override
  public String toXHTML() {
    return _escape ? Escape.html(_contents) : _contents;
  }

  public String getText() {
    return _contents;
  }
}

@@ -48,16 +48,55 @@
 e.ast;%0A%0A
+import java.lang.reflect.Constructor;%0A%0A
 import n
@@ -552,54 +552,1264 @@
 %0A%0A  
-public String getText() %7B%0A    return _contents
+/**%0A   * Get the (unescaped) text contained within this node.%0A   *%0A   * @return%0A   */%0A  public String getText() %7B%0A    return _contents;%0A  %7D%0A%0A  /**%0A   * Construct a new TextNode of the same type by appending the text of the%0A   * follower to this.%0A   */%0A  public TextNode append(String more) %7B%0A    String text = _contents + more;%0A%0A    // First try a constructor which just takes a string.%0A    try %7B%0A      Constructor%3C? extends TextNode%3E constructor = getClass().getDeclaredConstructor(String.class);%0A      return constructor.newInstance(text);%0A    %7D%0A%0A    // Fall back to the full constructor if there's no more specific%0A    // overridden one.%0A    catch (Exception e) %7B%0A      try %7B%0A        Constructor%3C? extends TextNode%3E constructor = getClass().getDeclaredConstructor(String.class, boolean.class);%0A        return constructor.newInstance(text, _escape);%0A      %7D%0A%0A      // See similar comments about judgement and shaming of subclass authors in%0A      // ASTNode::expandMacros.%0A      catch (Exception e2) %7B%0A        throw new RuntimeException(e2);%0A      %7D%0A    %7D%0A  %7D%0A%0A  /**%0A   * Construct a new TextNode of the same type by appending the text of the%0A   * follower to this.%0A   */%0A  public TextNode append(TextNode follower) %7B%0A    return append(follower.getText())
 ;%0A  

Add a TextNode::append method, to construct a new node with more text