info.bliki.wiki.tags.HTMLTag Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bliki-core Show documentation
Show all versions of bliki-core Show documentation
This is the core project.
The newest version!
package info.bliki.wiki.tags;
import info.bliki.htmlcleaner.TagNode;
import info.bliki.htmlcleaner.Utils;
import info.bliki.wiki.filter.ITextConverter;
import info.bliki.wiki.model.IWikiModel;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public class HTMLTag extends TagNode {
public final static boolean NEW_LINES = true;
// compile the regex, for better performance
protected final static Pattern XML_QNAME = Pattern.compile("^[_A-Za-z][\\w\\.\\-]*(:[_A-Za-z][\\w\\.\\-]*)?$");
public static void appendEscapedAttributes(Appendable buf, Map tagAtttributes) throws IOException {
if (tagAtttributes != null) {
for (Map.Entry currEntry : tagAtttributes.entrySet()) {
String attName = currEntry.getKey();
if (attName.length() >= 1 && Character.isLetter(attName.charAt(0))) {
// skip any invalid element names
// these usually come from bad markup input
// http://www.w3.org/TR/REC-xml-names/#NT-PrefixedName
if (!XML_QNAME.matcher(attName).matches()) {
continue;
}
String attValue = currEntry.getValue();
buf.append(" ");
buf.append(attName);
buf.append("=\"");
Utils.escapeXmlToBuffer(attValue, buf, false, false, false);
buf.append("\"");
}
}
}
}
public HTMLTag(String name) {
super(name);
}
public void appendAttributes(Appendable buf, Map tagAtttributes) throws IOException {
appendEscapedAttributes(buf, tagAtttributes);
}
public void renderHTML(ITextConverter converter, Appendable buf, IWikiModel model) throws IOException {
boolean newLinesAfterTag = false;
boolean newLinesAfterChildren = false;
TagNode node = this;
String name = node.getName();
List