package projet;

public class MarkdownBlocRenderer implements BlocRenderer {

	@Override
	public String renderTexte(String contenu) {
		return contenu + "\n";
	}

	@Override
	public String renderListe(String contenu, String style) {
        String[] items = contenu.split("\n");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < items.length; i++) {
            if ("number".equals(style)) {
                sb.append(i + 1).append(". ").append(items[i]).append("\n");
            } else {
                sb.append("- ").append(items[i]).append("\n");
            }
        }
        return sb.toString();
	}

	@Override
	public String renderTitre(String contenu, int level) {
		return "#".repeat(Math.max(1, level)) + " " + contenu + "\n";
	}

	@Override
	public String renderCode(String contenu, String language) {
		return "```" + language + "\n" + contenu + "\n```\n";
	}

	@Override
	public String renderPage(String title, String from) {
		return "[" + title + "](page:" + from + ")\n";
	}

	@Override
	public String renderSeparateur() {
		return "---\n";
	}

	@Override
	public String renderCitation(String contenu, String type) {
		StringBuilder result = new StringBuilder();
		String[] lignes = contenu.split("\n");
		for (String ligne : lignes) {
	        result.append("> ").append(ligne).append("\n");
	    }
		return result.toString();
	}
	

}
