
org.sweble.wikitext.engine.utils.HtmlPrinter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swc-engine Show documentation
Show all versions of swc-engine Show documentation
A minimal engine using the Sweble Wikitext Parser to
process articles in the context of a MediaWiki-like configuration.
/*
* This file is auto-generated.
* DO NOT MODIFY MANUALLY!
*
* Generated by AstNodeGenerator.
* Last generated: 2014-09-12 00:38:33.
*/
package org.sweble.wikitext.engine.utils;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import de.fau.cs.osr.ptk.common.ast.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.sweble.wikitext.engine.Page;
import org.sweble.wikitext.lazy.encval.*;
import org.sweble.wikitext.lazy.parser.*;
import org.sweble.wikitext.lazy.preprocessor.*;
import org.sweble.wikitext.lazy.utils.*;
public class HtmlPrinter
extends
de.fau.cs.osr.ptk.common.PrinterBase
{
public static String print(AstNode node, String articleTitle)
{
StringWriter writer = new StringWriter();
new HtmlPrinter(writer, articleTitle).go(node);
return writer.toString();
}
public static Writer print(Writer writer, AstNode node, String articleTitle)
{
new HtmlPrinter(writer, articleTitle).go(node);
return writer;
}
// =========================================================================
public void visit(AstNode astNode) throws IOException
{
print("");
print(astNode.getClass().getSimpleName());
print("");
}
public void visit(NodeList l) throws IOException
{
iterate(l);
}
public void visit(Page page) throws IOException
{
printNewline(false);
if (standaloneHtml) {
print("");
printNewline(true);
print("");
printNewline(true);
print("");
printNewline(true);
print("\t");
printNewline(true);
print("\t\t");
printNewline(true);
print("\t\t");
print(escHtml(articleTitle));
print(" ");
printNewline(false);
if (cssResource != null) {
print("\t");
} else if (cssFile != null) {
print("\t");
} else if (cssLink != null) {
print("\t");
}
printNewline(false);
print("\t");
printNewline(true);
print("\t");
printNewline(true);
}
print("");
printNewline(true);
print("\t");
print(escHtml(articleTitle));
print("
");
printNewline(true);
print("\t");
printNewline(false);
incIndent("\t\t");
iterate(page.getContent());
decIndent();
printNewline(false);
print("\t");
printNewline(true);
print("");
printNewline(true);
print("
"); printNewline(false); incIndent("\t"); iterate(p.getContent()); decIndent(); printNewline(false); print("
"); } printNewline(false); printNewline(false); } public void visit(SemiPre sp) throws IOException { printNewline(false); print(""); iterate(sp.getContent()); print(""); printNewline(false); } public void visit(SemiPreLine line) throws IOException { iterate(line.getContent()); print("\n"); } public void visit(Section s) throws IOException { printNewline(false); print("
");
printNewline(true);
print("\t");
iterate(s.getTitle());
print(" ");
printNewline(true);
print("\t
");
printNewline(false);
}
public void visit(XmlComment e) throws IOException
{
}
public void visit(XmlElement e) throws IOException
{
print("<");
print(e.getName());
iterate(e.getXmlAttributes());
if (e.getEmpty()) {
print(" />");
} else {
print(">");
iterate(e.getBody());
print("");
print(e.getName());
print(">");
}
}
public void visit(XmlAttribute a) throws IOException
{
print(" ");
print(a.getName());
print("=\"");
iterate(a.getValue());
print("\"");
}
public void visit(XmlAttributeGarbage g) throws IOException
{
}
public void visit(XmlCharRef ref) throws IOException
{
print("");
print(ref.getCodePoint());
print(";");
}
public void visit(XmlEntityRef ref) throws IOException
{
print("&");
print(ref.getName());
print(";");
}
public void visit(DefinitionList n) throws IOException
{
printNewline(false);
print("");
printNewline(false);
incIndent("\t\t");
iterate(s.getBody());
decIndent();
printNewline(false);
print("\t
");
printNewline(true);
print("- ");
printNewline(false);
incIndent("\t");
iterate(n.getContent());
decIndent();
printNewline(false);
print("
- ");
printNewline(false);
incIndent("\t");
iterate(n.getContent());
decIndent();
printNewline(false);
print("
- ");
printNewline(false);
incIndent("\t");
iterate(n.getContent());
decIndent();
printNewline(false);
print("
"); printNewline(false); } public void visit(Signature sig) throws IOException { print(""); print(makeSignature(sig)); print(""); } public void visit(Redirect n) throws IOException { print("↳ "); print(n.getTarget()); print(""); } public void visit(IllegalCodePoint n) throws IOException { print(""); print(asXmlCharRefs(n.getCodePoint())); print(""); } public void visit(MagicWord n) throws IOException { print("__"); print(n.getWord()); print("__"); } public void visit(TagExtension n) throws IOException { print(""); if (renderTagExtensions) { if (n.getBody().isEmpty()) { print("<"); print(n.getName()); iterate(n.getXmlAttributes()); print(" />"); } else { print("<"); print(n.getName()); iterate(n.getXmlAttributes()); print(">"); print(escHtml(n.getBody())); print("</"); print(n.getName()); print(">"); } } else { if (n.getXmlAttributes().isEmpty()) { print("<"); print(n.getName()); } else { print("<"); print(n.getName()); print(" ..."); } if (n.getBody().isEmpty()) { print("/>"); } else { print(">...</"); print(n.getName()); print(">"); } } print(""); } public void visit(XmlElementEmpty e) throws IOException { print(""); print("<"); print(e.getName()); iterate(e.getXmlAttributes()); print(" />"); print(""); } public void visit(XmlElementOpen e) throws IOException { print(""); print("<"); print(e.getName()); iterate(e.getXmlAttributes()); print(">"); print(""); } public void visit(XmlElementClose e) throws IOException { print(""); print("</"); print(e.getName()); print(">"); print(""); } public void visit(Template tmpl) throws IOException { print(""); if (renderTemplates) { print("{"); print("{"); iterate(tmpl.getName()); iterate(tmpl.getArgs()); print("}}"); } else { if (tmpl.getArgs().isEmpty()) { print("{"); print("{"); iterate(tmpl.getName()); print("}}"); } else { print("{"); print("{"); iterate(tmpl.getName()); print("|...}}"); } } print(""); } public void visit(TemplateParameter param) throws IOException { print(""); if (renderTemplates) { print("{"); print("{"); print("{"); iterate(param.getName()); dispatch(param.getDefaultValue()); iterate(param.getGarbage()); print("}}}"); } else { if (param.getDefaultValue() == null) { print("{"); print("{"); print("{"); iterate(param.getName()); print("}}}"); } else { print("{"); print("{"); print("{"); iterate(param.getName()); print("|...}}}"); } } print(""); } public void visit(TemplateArgument arg) throws IOException { print("|"); if (arg.getHasName()) { iterate(arg.getValue()); } else { iterate(arg.getName()); print("="); iterate(arg.getValue()); } } // ========================================================================= private String classPrefix; private String articleTitle = ""; private boolean renderTemplates = false; private boolean renderTagExtensions = false; private List