All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.gitbucket.markedj.Renderer Maven / Gradle / Ivy

package io.github.gitbucket.markedj;

import static io.github.gitbucket.markedj.Utils.*;

public class Renderer {

    protected Options options;

    public Renderer(Options options){
        this.options = options;
    }

    public String code(String code, String lang, boolean escaped){
        if(!isEmpty(lang)){
            StringBuilder sb = new StringBuilder();
            sb.append("
");
            if(escaped){
                sb.append(code);
            } else {
                sb.append(escape(code, true));
            }
            sb.append("\n
\n"); return sb.toString(); } else { StringBuilder sb = new StringBuilder(); sb.append("
");
            if(escaped){
                sb.append(code);
            } else {
                sb.append(escape(code, true));
            }
            sb.append("\n
\n"); return sb.toString(); } } public String blockquote(String quote){ return "
\n" + quote + "
\n"; } public String html(String html){ return html; } public String heading(String text, int level, String raw){ return "" + text + "\n"; } public String hr() { return "
\n"; } public String list(String body, boolean ordered){ String listType; if(ordered){ listType = "ol"; } else { listType = "ul"; } return "<" + listType + ">\n" + body + "\n"; } public String listitem(String text){ return "
  • " + text + "
  • \n"; } public String paragraph(String text){ return "

    " + text + "

    \n"; } public String table(String header, String body){ return "\n\n" + header + "\n\n" + body + "\n
    \n"; } public String tablerow(String content){ return "\n" + content + "\n"; } public String tablecell(String content, TableCellFlags flags){ String cellType; if(flags.isHeader()){ cellType = "th"; } else { cellType = "td"; } String align = flags.getAlign(); if(align != null){ return "<" + cellType + " style=\"text-align: " + align + "\">" + content + "\n"; } else { return "<" + cellType + ">" + content + "\n"; } } public String strong(String text){ return "" + text + ""; } public String em(String text){ return "" + text + ""; } public String codespan(String text){ return "" + text + ""; } public String br(){ return "
    "; } public String del(String text){ return "" + text + ""; } public String link(String href, String title, String text){ String titleAttr = ""; if(title != null){ titleAttr = " title=\"" + title + "\""; } return "" + text + ""; } public String image(String href, String title, String text){ String titleAttr = ""; if(title != null){ titleAttr = " title=\"" + title + "\""; } return "\"""; } public String nolink(String text){ return escape(text); } public String text(String text){ return text; } public static class TableCellFlags { private boolean header; private String align; public TableCellFlags(boolean header, String align){ this.header = header; this.align = align; } public boolean isHeader() { return header; } public String getAlign() { return align; } } }




    © 2015 - 2025 Weber Informatics LLC | Privacy Policy