de.undercouch.citeproc.csl.internal.format.HtmlFormat Maven / Gradle / Ivy
package de.undercouch.citeproc.csl.internal.format;
import de.undercouch.citeproc.csl.internal.RenderContext;
import de.undercouch.citeproc.csl.internal.SBibliography;
import de.undercouch.citeproc.csl.internal.TokenBuffer;
import de.undercouch.citeproc.output.Bibliography;
import de.undercouch.citeproc.output.SecondFieldAlign;
import org.apache.commons.text.StringEscapeUtils;
import static de.undercouch.citeproc.csl.internal.behavior.FormattingAttributes.FS_ITALIC;
import static de.undercouch.citeproc.csl.internal.behavior.FormattingAttributes.FW_BOLD;
import static de.undercouch.citeproc.csl.internal.behavior.FormattingAttributes.VA_SUP;
/**
* The HTML output format
* @author Michel Kraemer
*/
public class HtmlFormat extends BaseFormat {
@Override
public String getName() {
return "html";
}
@Override
protected String doFormatCitation(TokenBuffer buffer, RenderContext ctx) {
return format(buffer);
}
@Override
protected String doFormatBibliographyEntry(TokenBuffer buffer,
RenderContext ctx, int index) {
String result;
SecondFieldAlign sfa = ctx.getStyle().getBibliography().getSecondFieldAlign();
if (sfa != SecondFieldAlign.FALSE && !buffer.getTokens().isEmpty()) {
// find tokens that are part of the first field
int i = 0;
while (buffer.getTokens().get(i).isFirstField()) {
++i;
}
TokenBuffer firstBuffer = buffer.copy(0, i);
TokenBuffer restBuffer = buffer.copy(i, buffer.getTokens().size());
// render first field and rest independently
result = "\n " + format(firstBuffer) +
"" + format(restBuffer) + "\n ";
} else {
result = format(buffer);
}
return " " + result + "\n";
}
@Override
protected String doFormatLink(String text, String uri) {
return "" + text + "";
}
@Override
public Bibliography makeBibliography(String[] entries,
SBibliography bibliographyElement) {
SecondFieldAlign sfa = bibliographyElement.getSecondFieldAlign();
return new Bibliography(entries, "\n", "",
null, null, null, null, null, null, sfa);
}
@Override
protected String escape(String str) {
return StringEscapeUtils.escapeHtml4(str);
}
@Override
protected String openFontStyle(int fontStyle) {
if (fontStyle == FS_ITALIC) {
return "";
} else {
return "";
}
}
@Override
protected String closeFontStyle(int fontStyle) {
return "";
}
@Override
protected String openFontVariant(int fontVariant) {
return "";
}
@Override
protected String closeFontVariant(int fontVariant) {
return "";
}
@Override
protected String openFontWeight(int fontWeight) {
if (fontWeight == FW_BOLD) {
return "";
} else {
return "";
}
}
@Override
protected String closeFontWeight(int fontWeight) {
return "";
}
@Override
protected String openTextDecoration(int textDecoration) {
return "";
}
@Override
protected String closeTextDecoration(int textDecoration) {
return "";
}
@Override
protected String openVerticalAlign(int verticalAlign) {
if (verticalAlign == VA_SUP) {
return "";
} else {
return "";
}
}
@Override
protected String closeVerticalAlign(int verticalAlign) {
if (verticalAlign == VA_SUP) {
return "";
} else {
return "";
}
}
}