package org.zwobble.mammoth.html; import java.util.Map; import static org.zwobble.mammoth.util.MammothLists.orderedBy; public class HtmlWriter { public static String escapeText(String text) { return text.replace("&", "&").replace("<", "<").replace(">", ">"); } private static String escapeAttributeValue(String value) { return escapeText(value).replace("\"", """); } public static void generateAttributes(Map attributes, StringBuilder builder) { for (Map.Entry attribute : orderedBy(attributes.entrySet(), Map.Entry::getKey)) { builder .append(" ") .append(attribute.getKey()) .append("=\"") .append(HtmlWriter.escapeAttributeValue(attribute.getValue())) .append("\""); } } }