+ public @bind static class KeyVal extends Dump {
+ public @bind.arg String key;
+ public @bind.arg Text[] val;
+ }
+
+ public abstract static class Paragraph extends Dump implements ToHTML { }
+
+ public @bind.as("P") static class P extends Paragraph {
+ public Text[] text;
+ public P() { }
+ public P(Text[] text) { this.text = text; }
+ public P(String string) { this.text = new Text[] { new Chars(string) }; }
+ public void toHTML(HTML h) { if (text != null) for (Text t : text) if (t != null) t.toHTML(h); }
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ ToHTML.HTML h = new ToHTML.HTML(sb);
+ toHTML(h);
+ return sb.toString();
+ }
+ }
+
+ public static @bind class Login {
+ public @bind.arg String username;
+ public @bind.arg String password;
+ }
+
+ public static @bind.as("Euro") Object euro() { return null; }
+ public static @bind.as("Citation") Object cite(Object o) { return new Chars("*cite*"); }
+ public static @bind.as("Symbol") Object sym(Object o) { return null; }
+
+ public static abstract class List extends Text {
+ public @bind.arg Text[][] points;
+ public abstract String tag();
+ public void toHTML(ToHTML.HTML sb) {
+ sb.openTag(tag());
+ for(Text[] t : points)
+ sb.tag("li", t);
+ sb.closeTag(tag());
+ }
+ }
+ public static @bind class OL extends List { public String tag() { return "ol"; } }
+ public static @bind class UL extends List { public String tag() { return "ul"; } }
+
+ public static class HR extends Paragraph {
+ public @bind HR() { }
+ public @bind HR(Object o) { }
+ public void toHTML(HTML h) { h.tag("hr"); }
+ }
+
+ public static class Blockquote extends Paragraph {
+ Text[] text;
+ public @bind Blockquote(Text[] t) { this.text = t; }
+ public @bind Blockquote(Text[] t, Text[] t2) {
+ if (t2==null) {
+ this.text = t;
+ } else {
+ Text[] t3 = new Text[t.length + t2.length];
+ System.arraycopy(t, 0, t3, 0, t.length);
+ System.arraycopy(t2, 0, t3, t.length, t2.length);
+ this.text = t3;
+ }
+ }
+ public void toHTML(HTML h) { h.tag("blockquote", new P(text)); }
+ }
+
+ public abstract static class Text extends Dump implements ToHTML { }
+ public @bind static class Chars extends Text {
+ public String text;
+ public Chars() { }
+ public Chars(String text) { this.text = text; }
+ public void toHTML(HTML h) { h.appendText(" " + text + " "); }
+ public String toString() { return text; }
+ }
+ public @bind static class Block extends Text {
+ public Text[] text;
+ public void toHTML(HTML h) {
+ for(Text t : text)
+ if (t != null)
+ t.toHTML(h);
+ }
+ }
+ public static class TextWrap extends Text {
+ public @bind.arg Text[] text;
+ public void toHTML(HTML h) {
+ if (htmlTag()!=null) {
+ h.openTag(htmlTag(), htmlTagParams());
+ }
+ for(Text t : text) t.toHTML(h);
+ if (htmlTag()!=null) {
+ h.closeTag(htmlTag());
+ }
+ }
+ public String htmlTag() { return null; }
+ public Object[] htmlTagParams() { return null; }
+ }
+ public static @bind class Verbatim extends Text {
+ public @bind.arg String s;
+ public void toHTML(HTML h) {
+ h.openTag("div", new Object[] { "class", "terminal" });
+ for(int i=0; i<s.length(); i++) {
+ char c = s.charAt(i);
+ switch(c) {
+ case '\r': break;
+ case '\n': h.tag("br"); break;
+ case ' ': h.appendLiterally(" "); break;
+ default: h.appendText(c+""); break;
+ }
+ }
+ h.closeTag("div");
+ }
+ }
+ //public @bind class Blockquote extends TextWrap { }
+ public static @bind class Underline extends TextWrap { public String htmlTag() { return "u"; } }
+ public static @bind class Footnote extends TextWrap { public String htmlTag() { return "small"; } }
+ public static @bind class TT extends TextWrap { public String htmlTag() { return "tt"; } }
+ //public @bind class Citation extends Text { "[" word "]" }
+ public static @bind class Strikethrough extends TextWrap { public String htmlTag() { return "strike"; } }
+ public static @bind class Superscript extends TextWrap { public String htmlTag() { return "sup"; } }
+ public static @bind class Subscript extends TextWrap { public String htmlTag() { return "sub"; } }
+ public static @bind class Smallcap extends TextWrap { public String htmlTag() { return "sc"; } }
+ public static @bind class Keyword extends TextWrap { public String htmlTag() { return "sc"; } }
+ public static @bind class Bold extends TextWrap { public String htmlTag() { return "b"; } }
+ public static @bind class Italic extends TextWrap { public String htmlTag() { return "i"; } }
+
+ public abstract static class Command extends Text { }
+ public static @bind class Today extends Command { public void toHTML(HTML h) { } }
+ public static @bind class LineBreak extends Command { public void toHTML(HTML h) { h.tag("br"); } }
+
+ public static abstract class Glyph extends Text implements ToHTML { }
+ public static @bind.as("emdash") class Emdash extends Glyph { public void toHTML(HTML h) { h.appendLiterally("—"); } }
+ public static @bind.as("ellipses") class Ellipses extends Glyph { public void toHTML(HTML h) { h.appendLiterally("…"); } }
+ public static @bind.as("r") class RegTm extends Glyph { public void toHTML(HTML h) { h.appendLiterally("®"); } }
+ public static @bind.as("c") class Copyright extends Glyph { public void toHTML(HTML h) { h.appendLiterally("©"); } }
+ public static @bind.as("tm") class Tm extends Glyph { public void toHTML(HTML h) { h.appendLiterally("&;"); } }
+ public static @bind.as("euro") class Euro extends Glyph { public void toHTML(HTML h) { h.appendLiterally("€"); } }
+
+ public static @bind.as("#") Text comment() { return new Chars(""); }
+ public static class Entity extends Text implements ToHTML {
+ public int code;
+ public String name;
+ public Entity(String name, int code) { this.name = name; this.code = code; }
+ public Entity(String name, String abbrev, int code) { this(name, code); }
+ public void toHTML(HTML h) {
+ h.appendLiterally("&#x"+Integer.toString(code, 16)+";");
+ }
+ }
+
+ public static Entity[] entities = new Entity[] {
+ new Entity("tm", 0x2122),
+ new Entity("alef", 0x2135),
+ new Entity("leftArrow", "<--", 0x2190),
+ new Entity("rightArrow", "-->", 0x2192),
+ new Entity("leftDoubleArrow", "<==", 0x21D0),
+ new Entity("rightDoubleArrow", "==>", 0x21D2),
+ new Entity("doubleLeftRightArrow", "<==>", 0x21D4),
+ new Entity("upArrow", 0x2191),
+ new Entity("downArrow", 0x2193),
+ new Entity("upDoubleArrow", 0x21D1),
+ new Entity("downDoubleArrow", 0x21D3),
+ new Entity("forall", 0x2200),
+ new Entity("exists", 0x2203),
+ new Entity("emptySet", 0x2205),
+ new Entity("in", 0x2208),
+ new Entity("cent", 0xA2),
+ new Entity("pi", 0x220F),
+ new Entity("sigma", 0x2211),
+ new Entity("infinity", 0x221E),
+ new Entity("proportional", 0x221D),
+ new Entity("check", 0x221A),
+ new Entity("asterisk", 0x2217),
+ new Entity("minus", 0x2212),
+ new Entity("angle", 0x2220),
+ new Entity("and", 0x2227),
+ new Entity("or", 0x2228),
+ new Entity("intersection", 0x2229),
+ new Entity("union", 0x222A),
+ new Entity("integral", 0x222B),
+ new Entity("therefore", 0x2234),
+ new Entity("congruent", 0x2245),
+ new Entity("similarTo", 0x2248),
+ new Entity("identical", 0x2261),
+ new Entity("neq", 0x2260),
+ new Entity("subset", 0x2282),
+ new Entity("superset", 0x2283),
+ new Entity("notSubset", 0x2284),
+ new Entity("subsetEq", 0x2286),
+ new Entity("supersetEq", 0x2287),
+ new Entity("circlePlus", 0x2295),
+ new Entity("circleTimes", 0x2297),
+ new Entity("bottom", 0x22A5),
+ new Entity("cdot", 0x22C5),
+ new Entity("openDiamonds", 0x25CA),
+ new Entity("spade", 0x2660),
+ new Entity("clubs", 0x2663),
+ new Entity("hearts", 0x2665),
+ new Entity("diamonds", 0x2666),
+ new Entity("prime", 0x2032),
+ new Entity("reals", 0x211C),
+ new Entity("powerSet", 0x2118),
+ new Entity("overScore", 0x203E),
+ new Entity("yen", 0xA5),
+ new Entity("plusminus", 0xB1),
+ new Entity("micro", 0xB5),
+ new Entity("superScriptOne", 0xB9),
+ new Entity("superScriptTwo", 0xB2),
+ new Entity("superScriptThree", 0xB3),
+ new Entity("oneQuarter", 0xBC),
+ new Entity("oneHalf", 0xBD),
+ new Entity("threeQuarters", 0xBE),
+ new Entity("paragraphSymbol", 0xB6),
+ new Entity("times", 0xD7),
+ new Entity("daggar", 0x86),
+ new Entity("sectionSymbol", 0xA7),
+ new Entity("not", 0xAC),
+ new Entity("cr", 0x2193),
+ new Entity("dot", 0xB7),
+ };
+
+ public static @bind Object command(String s) {
+ if (s.equals("br")) return new LineBreak();
+ if (s.equals("today")) return new Today();
+ for(Entity e : entities)
+ if (e.name.equals(s))
+ return e;
+ return null;
+ }
+
+ public static class Link extends Text {
+ public Text[] t;
+ public Url u;
+ public Input.Region region;
+ public @bind.as("link") Link(Input.Region region, @bind.arg Text[] t, @bind.arg Url u) { this.region = region; this.t = t; this.u = u; }
+ public Link(String s, Url u) { this(null,new Text[] { new Chars(s) }, u); }
+ public void toHTML(HTML h) {
+ h.tag("a",
+ new Object[] { "href", u==null ? "" : u.toString() },
+ new P(/*t*/region+""));
+ }