<commit_before>package com.eden.orchid.languages.diagrams;

import com.eden.orchid.api.compilers.OrchidCompiler;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;

@Singleton
public class PlantUmlCompiler extends OrchidCompiler {

    @Inject
    public PlantUmlCompiler() {
        super(800);
    }

    @Override
    public String compile(String extension, String source, Map<String, Object> data) {
        try {
            try {
                // ensure string is wrapped in @startuml...@enduml
                source = source.trim();
                if(!source.startsWith("@startuml")) {
                    source = "@startuml\n" + source;
                }
                if(!source.endsWith("@enduml")) {
                    source = source + "\n@enduml";
                }

                // compile string to SVG
                ByteArrayOutputStream os = new ByteArrayOutputStream(1024);

                FileFormatOption fileFormat = new FileFormatOption(FileFormat.SVG);
                fileFormat.hideMetadata();

                SourceStringReader reader = new SourceStringReader(source);
                reader.outputImage(os, fileFormat);
                os.close();

                String s = new String(os.toByteArray(), Charset.forName("UTF-8"));
                s = s.replaceAll("<\\?(.*)\\?>", ""); // remove XML declaration

                return s;
            }
            catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }
        catch (Throwable e) {
            e.printStackTrace();
            return "";
        }
    }

    @Override
    public String getOutputExtension() {
        return "svg";
    }

    @Override
    public String[] getSourceExtensions() {
        return new String[]{"uml"};
    }
}<commit_msg>Allows support for other diagram types in PlantUmlCompiler<commit_after>package com.eden.orchid.languages.diagrams;

import com.eden.orchid.api.compilers.OrchidCompiler;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;

@Singleton
public class PlantUmlCompiler extends OrchidCompiler {

    private String[] tags = new String[] {
            "uml",
            "salt",
            "math",
            "latex",
            "gantt"
    };


    @Inject
    public PlantUmlCompiler() {
        super(800);
    }

    @Override
    public String compile(String extension, String source, Map<String, Object> data) {
        try {
            try {
                // ensure string is wrapped in @startuml...@enduml
                source = source.trim();
                source = wrapDiagram(source);

                // compile string to SVG
                ByteArrayOutputStream os = new ByteArrayOutputStream(1024);

                FileFormatOption fileFormat = new FileFormatOption(FileFormat.SVG);
                fileFormat.hideMetadata();

                SourceStringReader reader = new SourceStringReader(source);
                reader.outputImage(os, fileFormat);
                os.close();

                String s = new String(os.toByteArray(), Charset.forName("UTF-8"));
                s = s.replaceAll("<\\?(.*)\\?>", ""); // remove XML declaration

                return s;
            }
            catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }
        catch (Throwable e) {
            e.printStackTrace();
            return "";
        }
    }

    @Override
    public String getOutputExtension() {
        return "svg";
    }

    @Override
    public String[] getSourceExtensions() {
        return new String[]{"uml"};
    }

    private String wrapDiagram(String input) {
        boolean isWrapped = false;

        String source = input;

        for(String tag : tags) {
            if(source.startsWith("@start" + tag)) {
                isWrapped = true;
                break;
            }
            if(source.endsWith("@end" + tag)) {
                isWrapped = true;
                break;
            }
        }

        if(!isWrapped) {
            source = "@startuml\n" + source;
            source = source + "\n@enduml";
        }

        return source;
    }
}
{'fraction_non_alphanumeric': 0.10729342327150085, 'fraction_numerical': 0.003372681281618887, 'mean_word_length': 1.78462441314554, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3756851', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1232, 'n_words': 273}