![JAR search and dependency download from the Maven repository](/logo.png)
net.java.textilej.parser.TextileParser Maven / Gradle / Ivy
The newest version!
package net.java.textilej.parser;
import java.io.StringWriter;
import net.java.textilej.parser.builder.HtmlDocumentBuilder;
import net.java.textilej.parser.markup.Dialect;
import net.java.textilej.parser.markup.textile.TextileDialect;
/**
* A parser that parses basic Textile markup and converts it to HTML.
*
* Based on the spec available at http://textile.thresholdstate.com/,
* supports basic phrase modifiers, block modifiers, attributes, footnotes, and some punctuation.
*
* Additionally supported are {toc}
and {glossary}
.
*
* The supported syntax of the parser may be augmented by {@link #setDialect(Dialect) setting a dialect}.
* Without adding a dialect the base syntax of the parser supports true Textile markup, with the addition of the following:
*
* - Support for {toc} and {glossary}
* - lists that start with '-'
* - Confluence-style table headers
*
*
* @author dgreen
*
* @deprecated use {@link MarkupParser}
*/
@Deprecated
public class TextileParser {
private DocumentBuilder builder;
/**
* parse the given textile string and produce the result as an HTML document.
*
* @param textile the textile to parse
*
* @return the HTML document text.
*/
public String parseToHtml(String textile) {
if (builder != null) {
throw new IllegalStateException("parseToHtml cannot be called if builder is set");
}
StringWriter out = new StringWriter();
setBuilder(new HtmlDocumentBuilder(out));
parse(textile);
setBuilder(null);
return out.toString();
}
/**
* parse the given Textile markup string and emit the results as an HTML document to
* the given writer. The given writer is closed upon return of this function.
*
* @param textile the Textile markup
*/
public void parse(String textile) {
parse(textile,true);
}
/**
* parse the given Textile markup string and emit the results as an HTML document to
* the given writer. The given writer is closed upon return of this function.
*
* if asDocument
is specified, the {@link #getBuilder() builder} is treated as a document
* ({@link DocumentBuilder#beginDocument()} and {@link DocumentBuilder#endDocument()} are called).
*
* @param textile the Textile markup
* @param asDocument if true, the {@link #getBuilder() builder} is treated as a document
*/
public void parse(String textile,boolean asDocument) {
if (builder == null) {
throw new IllegalStateException("Must set builder");
}
MarkupParser parser = new MarkupParser();
parser.setDialect(new TextileDialect());
parser.setBuilder(builder);
parser.parse(textile, asDocument);
}
public void setBuilder(DocumentBuilder builder) {
this.builder = builder;
}
public DocumentBuilder getBuilder() {
return builder;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy