markwon-core/src/main/java/ru/noties/markwon/MarkwonBuilderImpl.java
@VisibleForTesting
    @NonNull
    static List<MarkwonPlugin> ensureImplicitCoreIfHasDependents(@NonNull List<MarkwonPlugin> plugins) {
        // loop over plugins -> if CorePlugin is found -> break;
        // iterate over all plugins and check if CorePlugin is requested

        boolean hasCore = false;
        boolean hasCoreDependents = false;

        for (MarkwonPlugin plugin : plugins) {

            // here we do not check for exact match (a user could've subclasses CorePlugin
            // and supplied it. In this case we DO NOT implicitly add CorePlugin
            //
            // if core is present already we do not need to iterate anymore -> as nothing
            // will be changed (and we actually do not care if there are any dependents of Core
            // as it's present anyway)
            if (CorePlugin.class.isAssignableFrom(plugin.getClass())) {
                hasCore = true;
                break;
            }

            // if plugin has CorePlugin in dependencies -> mark for addition
            if (!hasCoreDependents) {
                // here we check for direct CorePlugin, if it's not CorePlugin (exact, not a subclass
                // or something -> ignore)
                if (plugin.priority().after().contains(CorePlugin.class)) {
                    hasCoreDependents = true;
                }
            }
        }

        // important thing here is to check if corePlugin is added
        // add it _only_ if it's not present
        if (hasCoreDependents && !hasCore) {
            final List<MarkwonPlugin> out = new ArrayList<>(plugins.size() + 1);
            // add default instance of CorePlugin
            out.add(CorePlugin.create());
            out.addAll(plugins);
            return out;
        }

        return plugins;
    }
@VisibleForTesting
    @NonNull
    static List<MarkwonPlugin> ensureImplicitCoreIfHasDependents(@NonNull List<MarkwonPlugin> plugins) {
        // loop over plugins -> if CorePlugin is found -> break;
        // iterate over all plugins and check if CorePlugin is requested

        boolean hasCore = false;
        boolean hasCoreDependents = false;

        for (MarkwonPlugin plugin : plugins) {

            // here we do not check for exact match (a user could've subclasses CorePlugin
            // and supplied it. In this case we DO NOT implicitly add CorePlugin
            //
            // if core is present already we do not need to iterate anymore -> as nothing
            // will be changed (and we actually do not care if there are any dependents of Core
            // as it's present anyway)
            if (CorePlugin.class.isAssignableFrom(plugin.getClass())) {
                hasCore = true;
                break;
            }

            // if plugin has CorePlugin in dependencies -> mark for addition
            if (!hasCoreDependents) {
                // here we check for direct CorePlugin, if it's not CorePlugin (exact, not a subclass
                // or something -> ignore)
                if (plugin.priority().after().contains(CorePlugin.class)) {
                    hasCoreDependents = true;
                }
            }
        }

        // important thing here is to check if corePlugin is added
        // add it _only_ if it's not present
        if (hasCoreDependents && !hasCore) {
            final List<MarkwonPlugin> out = new ArrayList<>(plugins.size() + 1);
            // add default instance of CorePlugin
            out.add(CorePlugin.create());
            out.addAll(plugins);
            return out;
        }

        return plugins;
    }
@ VisibleForTesting @ NonNull static List < MarkwonPlugin > ensureImplicitCoreIfHasDependents ( @ NonNull List < MarkwonPlugin > plugins ) { // loop over plugins -> if CorePlugin is found -> break; // iterate over all plugins and check if CorePlugin is requested boolean hasCore = false ; boolean hasCoreDependents = false ; for ( MarkwonPlugin plugin : plugins ) { // here we do not check for exact match (a user could've subclasses CorePlugin // and supplied it. In this case we DO NOT implicitly add CorePlugin // // if core is present already we do not need to iterate anymore -> as nothing // will be changed (and we actually do not care if there are any dependents of Core // as it's present anyway) if ( CorePlugin . class . isAssignableFrom ( plugin . getClass ( ) ) ) { hasCore = true ; break ; } // if plugin has CorePlugin in dependencies -> mark for addition if ( ! hasCoreDependents ) { // here we check for direct CorePlugin, if it's not CorePlugin (exact, not a subclass // or something -> ignore) if ( plugin . priority ( ) . after ( ) . contains ( CorePlugin . class ) ) { hasCoreDependents = true ; } } } // important thing here is to check if corePlugin is added // add it _only_ if it's not present if ( hasCoreDependents && ! hasCore ) { final List < MarkwonPlugin > out = new ArrayList <> ( plugins . size ( ) + 1 ) ; // add default instance of CorePlugin out . add ( CorePlugin . create ( ) ) ; out . addAll ( plugins ) ; return out ; } return plugins ; }
that depends on CorePlugin
that depends on CorePlugin