private String getChapter(String wikiText, int headerIdx){
        int startIdx = wikiText.lastIndexOf('\n', headerIdx) + 1;
        int endIdx = wikiText.indexOf('\n', headerIdx);
        if(endIdx == -1){
            return wikiText.substring(startIdx);
        }
        String header = wikiText.substring(startIdx, endIdx).trim();
        int prefixSize = 0;
        while(header.length() > prefixSize && header.charAt(prefixSize) == '='){
            prefixSize++;
        }
        if(prefixSize == 0){
            return wikiText.substring(startIdx);
        }
        String marker = header.substring(0,prefixSize);
        if(!header.endsWith(marker)){
            return wikiText.substring(startIdx);
        }

        Pattern pattern = Pattern.compile( "^" + marker + "[^=].*[^=]" + marker + "\\s*$", Pattern.MULTILINE );
        Matcher matcher = pattern.matcher( wikiText );

        if( matcher.find( endIdx ) ) {
            String chapter = wikiText.substring(startIdx, matcher.start() ).trim();
            if(header.equals(chapter)){
                return wikiText.substring(startIdx); //there is some things wrong in the structure
            }
            return chapter;
        }
            
        return wikiText.substring(startIdx);
    }