src/main/java/de/nycode/bankobot/docdex/FlexmarkUtils.java
/**
     * Modification of {@link HtmlConverterCoreNodeRenderer#processPre(Element,
     * HtmlNodeConverterContext, HtmlMarkdownWriter)} which makes all codeblock java.
     * It also removes some weird new lines that are not needed
     */
Modification of {@link HtmlConverterCoreNodeRenderer#processPre(Element,
HtmlNodeConverterContext, HtmlMarkdownWriter)} which makes all codeblock java.
It also removes some weird new lines that are not needed
Modification of { @link HtmlConverterCoreNodeRenderer#processPre ( Element HtmlNodeConverterContext HtmlMarkdownWriter ) } which makes all codeblock java . It also removes some weird new lines that are not needed
@SuppressWarnings("JavadocReference")
    static void processPre(Element element, HtmlNodeConverterContext context,
                           HtmlMarkdownWriter out) {
        context.pushState(element);
        String text;
        boolean hadCode = false;
        String className = "";
        HtmlNodeConverterContext preText = context.getSubContext();
        preText.getMarkdown().setOptions(out.getOptions() & ~(LineAppendable.F_COLLAPSE_WHITESPACE
                | LineAppendable.F_TRIM_TRAILING_WHITESPACE));
        preText.getMarkdown().openPreFormatted(false);
        Node next;
        while ((next = context.next()) != null) {
            if (next.nodeName().equalsIgnoreCase("code") || next.nodeName().equalsIgnoreCase("tt")) {
                hadCode = true;
                Element code = (Element) next;
                preText.renderChildren(code, false, null);
                if (className.isEmpty()) {
                    className = Utils
                            .removePrefix(code.className(), "language-");
                }
            } else if (next.nodeName().equalsIgnoreCase("br")) {
                preText.getMarkdown().append("\n");
            } else if (next.nodeName().equalsIgnoreCase("#text")) {
                preText.getMarkdown().append(((TextNode) next).getWholeText());
            } else {
                preText.renderChildren(next, false, null);
            }
        }
        preText.getMarkdown().closePreFormatted();
        text = preText.getMarkdown().toString(Integer.MAX_VALUE, 2);
        int backTickCount = HtmlConverterCoreNodeRenderer.getMaxRepeatedChars(text, '`', 3);
        CharSequence backTicks = RepeatedSequence.repeatOf("`", backTickCount);
        if ((!className.isEmpty() || text.trim().isEmpty() || !hadCode)) {
            out.append(backTicks).append("java").append("\n");
            if (!className.isEmpty()) {
                out.append(className);
            }
            out.line();
            out.openPreFormatted(true);
            if (!text.isBlank() && !text.equals("\n")) {
                if (text.endsWith("\n \n")) {
                    out.append(text.substring(0, text.indexOf("\n \n")));
                } else {
                    out.append(text);
                }
            }
            out.closePreFormatted();
            out.append(backTicks);
        } else {
            out.pushPrefix();
            out.openPreFormatted(true);
            if (!text.isBlank()) {
                out.append(text);
            }
            out.closePreFormatted();
            out.line();
            out.popPrefix();
        }
        context.popState(out);
    }
@ SuppressWarnings ( "JavadocReference" ) static void processPre ( Element element , HtmlNodeConverterContext context , HtmlMarkdownWriter out ) { context . pushState ( element ) ; String text ; boolean hadCode = false ; String className = "" ; HtmlNodeConverterContext preText = context . getSubContext ( ) ; preText . getMarkdown ( ) . setOptions ( out . getOptions ( ) & ~ ( LineAppendable . F_COLLAPSE_WHITESPACE | LineAppendable . F_TRIM_TRAILING_WHITESPACE ) ) ; preText . getMarkdown ( ) . openPreFormatted ( false ) ; Node next ; while ( ( next = context . next ( ) ) != null ) { if ( next . nodeName ( ) . equalsIgnoreCase ( "code" ) || next . nodeName ( ) . equalsIgnoreCase ( "tt" ) ) { hadCode = true ; Element code = ( Element ) next ; preText . renderChildren ( code , false , null ) ; if ( className . isEmpty ( ) ) { className = Utils . removePrefix ( code . className ( ) , "language-" ) ; } } else if ( next . nodeName ( ) . equalsIgnoreCase ( "br" ) ) { preText . getMarkdown ( ) . append ( "\n" ) ; } else if ( next . nodeName ( ) . equalsIgnoreCase ( "#text" ) ) { preText . getMarkdown ( ) . append ( ( ( TextNode ) next ) . getWholeText ( ) ) ; } else { preText . renderChildren ( next , false , null ) ; } } preText . getMarkdown ( ) . closePreFormatted ( ) ; text = preText . getMarkdown ( ) . toString ( Integer . MAX_VALUE , 2 ) ; int backTickCount = HtmlConverterCoreNodeRenderer . getMaxRepeatedChars ( text , '`' , 3 ) ; CharSequence backTicks = RepeatedSequence . repeatOf ( "`" , backTickCount ) ; if ( ( ! className . isEmpty ( ) || text . trim ( ) . isEmpty ( ) || ! hadCode ) ) { out . append ( backTicks ) . append ( "java" ) . append ( "\n" ) ; if ( ! className . isEmpty ( ) ) { out . append ( className ) ; } out . line ( ) ; out . openPreFormatted ( true ) ; if ( ! text . isBlank ( ) && ! text . equals ( "\n" ) ) { if ( text . endsWith ( "\n \n" ) ) { out . append ( text . substring ( 0 , text . indexOf ( "\n \n" ) ) ) ; } else { out . append ( text ) ; } } out . closePreFormatted ( ) ; out . append ( backTicks ) ; } else { out . pushPrefix ( ) ; out . openPreFormatted ( true ) ; if ( ! text . isBlank ( ) ) { out . append ( text ) ; } out . closePreFormatted ( ) ; out . line ( ) ; out . popPrefix ( ) ; } context . popState ( out ) ; }
Modification of {@link HtmlConverterCoreNodeRenderer#processPre(Element,
 HtmlNodeConverterContext, HtmlMarkdownWriter)} which makes all codeblock java.
Modification of { @link HtmlConverterCoreNodeRenderer#processPre ( Element HtmlNodeConverterContext HtmlMarkdownWriter ) } which makes all codeblock java .
//text = code.toString(); // Javadcoc is stupid and adds two new lines at the end of each codeblock which just looks // odd in discord so we're going to get rid of those // we indent the whole thing by 4 spaces