package org.simantics.scl.compiler.internal.parsing.documentation;
import java.io.IOException;
import java.io.StringReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.simantics.scl.compiler.elaboration.modules.Documentation;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
public abstract class HtmlUnparsingContext {
StringBuilder stringBuilder;
String listLevel = "";
int tableOfContentsLevel = 0;
StringBuilder tableOfContents;
int headerLinkId = 0;
public HtmlUnparsingContext(StringBuilder stringBuilder) {
this.stringBuilder = stringBuilder;
this.tableOfContents = null;
}
public HtmlUnparsingContext() {
this(new StringBuilder());
tableOfContents = new StringBuilder();
}
public StringBuilder getStringBuilder() {
return stringBuilder;
}
public StringBuilder getTableOfContents() {
return tableOfContents;
}
public void finishTableOfContents() {
while(tableOfContentsLevel > 0) {
tableOfContents.append("\n");
--tableOfContentsLevel;
}
}
public void header(int level, String text) {
clear();
++headerLinkId;
stringBuilder.append("
");
Matcher m = PARAGRAPH_PATTERN.matcher(text);
int lastAppend = 0;
while(m.find()) {
int start = m.start();
int end = m.end();
stringBuilder.append(text, lastAppend, start);
char c = text.charAt(start);
if(c == '\'') {
String ref = text.substring(start+1, end-1);
stringBuilder.append("")
.append(ref)
.append("
");
}
else if(c == '@') {
stringBuilder.append("").append(text, start+1, end-1).append("
");
}
lastAppend = end;
}
stringBuilder.append(text, lastAppend, text.length());
stringBuilder.append("