def jupyterbook():
    '\n    Create content and TOC for building a jupyter-book version 0.8: https://jupyterbook.org/intro\n\n    This function is called directly from bin/doconce\n    '
    if (len(sys.argv) < 2):
        doconce_version()
        print(docstring_jupyterbook)
        print("Try 'doconce jupyterbook --help' for more information.")
        sys.exit(1)
    if (option('help') or ('-h' in sys.argv)):
        print_help_jupyterbook()
        sys.exit(1)
    if (not check_command_line_options(1, option_list=(_legal_cmdline_opts_jupyterbook + _legal_command_line_options))):
        _abort()
    dest = option('dest=', default='./', option_list=_legal_cmdline_opts_jupyterbook)
    dest = folder_checker(dest)
    dest_toc = option('dest_toc=', default='./', option_list=_legal_cmdline_opts_jupyterbook)
    dest_toc = folder_checker(dest_toc)
    sep = option('sep=', default='section', option_list=_legal_cmdline_opts_jupyterbook)
    sep_section = option('sep_section=', default='', option_list=_legal_cmdline_opts_jupyterbook)
    globals.encoding = option('encoding=', default='')
    titles_opt = option('titles=', default='auto', option_list=_legal_cmdline_opts_jupyterbook)
    show_titles_opt = option('show_titles', default=False, option_list=_legal_cmdline_opts_jupyterbook)
    (dirname, basename, ext, filename) = find_file_with_extensions(sys.argv[1], allowed_extensions=['.do.txt'])
    if (not filename):
        errwarn(('*** error: file %s does not exist' % globals.filename))
        _abort()
    globals.dirname = dirname
    if dirname:
        os.chdir(dirname)
        errwarn(('*** doconce format now works in directory %s' % dirname))
        dest = (os.path.relpath((dest or '.'), start=dirname) + '/')
        if dest.startswith('./'):
            dest = dest[2:]
        dest_toc = (os.path.relpath((dest_toc or '.'), start=dirname) + '/')
        if dest_toc.startswith('./'):
            dest_toc = dest_toc[2:]
    globals.filename = filename
    globals.dofile_basename = basename
    _rmdolog()
    preprocessor_options = [arg for arg in sys.argv[1:] if (not arg.startswith('--'))]
    format = 'pandoc'
    filename_preprocessed = preprocess(globals.filename, format, preprocessor_options)
    filestr = read_file(filename_preprocessed, _encoding=globals.encoding)
    for tag in ('TITLE', 'AUTHOR', 'DATE'):
        if re.search(('^%s:.*' % tag), filestr, re.MULTILINE):
            errwarn(('*** warning : Removing heading with %s. Consider to place it in _config.yml' % tag.lower()))
        filestr = re.sub(('^%s:.*' % tag), '', filestr, flags=re.MULTILINE)
    tag = 'TOC'
    if re.search(('^%s:.*' % tag), filestr, re.MULTILINE):
        errwarn(('*** warning : Removing the %s tag' % tag.lower()))
        filestr = re.sub(('^%s:.*' % tag), '', filestr, flags=re.MULTILINE)
    pattern_tag = '[\\w _\\-]*'
    pattern = (((('cite(?:(\\[' + pattern_tag) + '\\]))?\\{(') + pattern_tag) + ')\\}')
    if re.search(pattern, filestr):
        filestr = handle_index_and_bib(filestr, 'html')
    m = re.search('\\A\\s*^(?:#.*\\s*|!split\\s*)*', filestr, re.MULTILINE)
    if m:
        filestr = filestr[m.end():]
    "skip = ''\n    for line in filestr.splitlines():\n        if not line.strip():\n            skip += line + '\n'\n        elif not line.startswith('#') and not line.startswith('!'):\n            break\n        else:\n            skip += line +'\n'\n    filestr = filestr[len(skip):]\n    "
    chapters = split_file(filestr, INLINE_TAGS[sep])
    sec_list = ([[]] * len(chapters))
    sec_title_list_auto = None
    if sep_section:
        for (c, chap) in enumerate(chapters):
            m = re.search(INLINE_TAGS[sep_section], chap, flags=re.MULTILINE)
            if m:
                pos_sep_section = (m.start() if m else 0)
                chapters[c] = split_file(chap[:pos_sep_section], INLINE_TAGS[sep_section])[0]
                sec_list[c] = split_file(chap[pos_sep_section:], INLINE_TAGS[sep_section])
    (chapter_titles, sec_title_list) = read_title_file(titles_opt, chapters, sec_list)

    def int_formatter(_list):
        return (('%0' + str(max(2, (math.floor(math.log((len(_list) + 0.01), 10)) + 1)))) + 'd_')
    chapter_formatter = int_formatter(chapters)
    (chapters, chapter_titles, chapter_titles_auto) = titles_to_chunks(chapters, chapter_titles, sep=sep, chapter_formatter=chapter_formatter, tags=INLINE_TAGS)
    chapter_basenames = [((chapter_formatter % (i + 1)) + basename) for i in range(len(chapters))]
    sec_basename_list = ([[]] * len(chapters))
    if sep_section:
        sec_title_list_auto = ([[]] * len(sec_title_list))
        for (c, sections) in enumerate(sec_list):
            section_formatter = ((chapter_formatter % (c + 1)) + int_formatter(sections))
            (sec_list[c], section_titles, section_titles_auto) = titles_to_chunks(sections, sec_title_list[c], sep=sep_section, sep2=sep, chapter_formatter=section_formatter, tags=INLINE_TAGS)
            sec_title_list[c] = section_titles
            sec_title_list_auto[c] = section_titles_auto
            sec_basename_list[c] = [((section_formatter % (i + 1)) + basename) for i in range(len(sections))]
    if show_titles_opt:
        if (sep_section == ''):
            print(('\n===== Titles detected using the %s separator:' % sep))
        else:
            print(('\n===== Titles detected using the %s and %s separators:' % (sep, sep_section)))
        for c in range(len(chapter_titles_auto)):
            print(chapter_titles_auto[c])
            if sep_section:
                for s in range(len(sec_title_list_auto[c])):
                    print(sec_title_list_auto[c][s])
        print('=====')
    all_texts = []
    all_basenames = []
    all_titles = []
    all_nestings = []
    for c in range(len(chapters)):
        all_texts.append(chapters[c])
        all_basenames.append(chapter_basenames[c])
        all_titles.append(chapter_titles[c])
        all_nestings.append(0)
        for s in range(len(sec_list[c])):
            all_texts.append(sec_list[c][s])
            all_basenames.append(sec_basename_list[c][s])
            all_titles.append(sec_title_list[c][s])
            all_nestings.append(1)
    all_suffix = identify_format(all_texts)
    all_fnames = [(b + s) for (b, s) in zip(all_basenames, all_suffix)]
    all_markings = list(map((lambda x: ('!split\n<!-- jupyter-book %s -->\n' % x)), all_fnames))
    all_texts = [(m + t) for (m, t) in zip(all_markings, all_texts)]
    filestr = ''.join(all_texts)
    (filestr_md, bg_session) = doconce2format(filestr, 'pandoc')
    (filestr_ipynb, bg_session) = doconce2format(filestr, 'ipynb')
    all_texts_md = split_file(filestr_md, '<!-- !split -->\n<!-- jupyter-book .* -->\n')
    all_texts_ipynb = split_ipynb(filestr_ipynb, all_fnames)
    if (len(all_texts_md) != len(all_texts_ipynb)):
        errwarn('*** error : the lengths of .md and .ipynb files should be the same')
        _abort()
    all_texts_formatted = ([[]] * len(all_fnames))
    for i in range(len(all_fnames)):
        all_texts_formatted[i] = all_texts_md[i]
        if all_fnames[i].endswith('.ipynb'):
            all_texts_formatted[i] = all_texts_ipynb[i]
    all_texts_formatted = resolve_links_destinations(all_texts_formatted, all_basenames)
    all_texts_formatted = [fix_media_src(t, '', dest) for t in all_texts_formatted]
    for i in range(len(all_texts_formatted)):
        write_file(all_texts_formatted[i], (dest + all_fnames[i]), _encoding=globals.encoding)
    yml_text = create_toc_yml(all_basenames, titles=all_titles, nesting_levels=all_nestings, dest=dest, dest_toc=dest_toc)
    write_file(yml_text, (dest_toc + '_toc.yml'), _encoding=globals.encoding)
    print(('\nWrote _toc.yml and %d chapter files to these folders:\n  %s\n  %s' % (len(all_fnames), os.path.realpath(dest_toc), os.path.realpath(dest))))
Create content and TOC for building a jupyter-book version 0.8: https://jupyterbook.org/intro

This function is called directly from bin/doconce
def jupyterbook():
    '\n    Create content and TOC for building a jupyter-book version 0.8: https://jupyterbook.org/intro\n\n    This function is called directly from bin/doconce\n    '
    if (len(sys.argv) < 2):
        doconce_version()
        print(docstring_jupyterbook)
        print("Try 'doconce jupyterbook --help' for more information.")
        sys.exit(1)
    if (option('help') or ('-h' in sys.argv)):
        print_help_jupyterbook()
        sys.exit(1)
    if (not check_command_line_options(1, option_list=(_legal_cmdline_opts_jupyterbook + _legal_command_line_options))):
        _abort()
    dest = option('dest=', default='./', option_list=_legal_cmdline_opts_jupyterbook)
    dest = folder_checker(dest)
    dest_toc = option('dest_toc=', default='./', option_list=_legal_cmdline_opts_jupyterbook)
    dest_toc = folder_checker(dest_toc)
    sep = option('sep=', default='section', option_list=_legal_cmdline_opts_jupyterbook)
    sep_section = option('sep_section=', default=, option_list=_legal_cmdline_opts_jupyterbook)
    globals.encoding = option('encoding=', default=)
    titles_opt = option('titles=', default='auto', option_list=_legal_cmdline_opts_jupyterbook)
    show_titles_opt = option('show_titles', default=False, option_list=_legal_cmdline_opts_jupyterbook)
    (dirname, basename, ext, filename) = find_file_with_extensions(sys.argv[1], allowed_extensions=['.do.txt'])
    if (not filename):
        errwarn(('*** error: file %s does not exist' % globals.filename))
        _abort()
    globals.dirname = dirname
    if dirname:
        os.chdir(dirname)
        errwarn(('*** doconce format now works in directory %s' % dirname))
        dest = (os.path.relpath((dest or '.'), start=dirname) + '/')
        if dest.startswith('./'):
            dest = dest[2:]
        dest_toc = (os.path.relpath((dest_toc or '.'), start=dirname) + '/')
        if dest_toc.startswith('./'):
            dest_toc = dest_toc[2:]
    globals.filename = filename
    globals.dofile_basename = basename
    _rmdolog()
    preprocessor_options = [arg for arg in sys.argv[1:] if (not arg.startswith('--'))]
    format = 'pandoc'
    filename_preprocessed = preprocess(globals.filename, format, preprocessor_options)
    filestr = read_file(filename_preprocessed, _encoding=globals.encoding)
    for tag in ('TITLE', 'AUTHOR', 'DATE'):
        if re.search(('^%s:.*' % tag), filestr, re.MULTILINE):
            errwarn(('*** warning : Removing heading with %s. Consider to place it in _config.yml' % tag.lower()))
        filestr = re.sub(('^%s:.*' % tag), , filestr, flags=re.MULTILINE)
    tag = 'TOC'
    if re.search(('^%s:.*' % tag), filestr, re.MULTILINE):
        errwarn(('*** warning : Removing the %s tag' % tag.lower()))
        filestr = re.sub(('^%s:.*' % tag), , filestr, flags=re.MULTILINE)
    pattern_tag = '[\\w _\\-]*'
    pattern = (((('cite(?:(\\[' + pattern_tag) + '\\]))?\\{(') + pattern_tag) + ')\\}')
    if re.search(pattern, filestr):
        filestr = handle_index_and_bib(filestr, 'html')
    m = re.search('\\A\\s*^(?:#.*\\s*|!split\\s*)*', filestr, re.MULTILINE)
    if m:
        filestr = filestr[m.end():]
    "skip = \n    for line in filestr.splitlines():\n        if not line.strip():\n            skip += line + '\n'\n        elif not line.startswith('#') and not line.startswith('!'):\n            break\n        else:\n            skip += line +'\n'\n    filestr = filestr[len(skip):]\n    "
    chapters = split_file(filestr, INLINE_TAGS[sep])
    sec_list = ([[]] * len(chapters))
    sec_title_list_auto = None
    if sep_section:
        for (c, chap) in enumerate(chapters):
            m = re.search(INLINE_TAGS[sep_section], chap, flags=re.MULTILINE)
            if m:
                pos_sep_section = (m.start() if m else 0)
                chapters[c] = split_file(chap[:pos_sep_section], INLINE_TAGS[sep_section])[0]
                sec_list[c] = split_file(chap[pos_sep_section:], INLINE_TAGS[sep_section])
    (chapter_titles, sec_title_list) = read_title_file(titles_opt, chapters, sec_list)

    def int_formatter(_list):
        return (('%0' + str(max(2, (math.floor(math.log((len(_list) + 0.01), 10)) + 1)))) + 'd_')
    chapter_formatter = int_formatter(chapters)
    (chapters, chapter_titles, chapter_titles_auto) = titles_to_chunks(chapters, chapter_titles, sep=sep, chapter_formatter=chapter_formatter, tags=INLINE_TAGS)
    chapter_basenames = [((chapter_formatter % (i + 1)) + basename) for i in range(len(chapters))]
    sec_basename_list = ([[]] * len(chapters))
    if sep_section:
        sec_title_list_auto = ([[]] * len(sec_title_list))
        for (c, sections) in enumerate(sec_list):
            section_formatter = ((chapter_formatter % (c + 1)) + int_formatter(sections))
            (sec_list[c], section_titles, section_titles_auto) = titles_to_chunks(sections, sec_title_list[c], sep=sep_section, sep2=sep, chapter_formatter=section_formatter, tags=INLINE_TAGS)
            sec_title_list[c] = section_titles
            sec_title_list_auto[c] = section_titles_auto
            sec_basename_list[c] = [((section_formatter % (i + 1)) + basename) for i in range(len(sections))]
    if show_titles_opt:
        if (sep_section == ):
            print(('\n===== Titles detected using the %s separator:' % sep))
        else:
            print(('\n===== Titles detected using the %s and %s separators:' % (sep, sep_section)))
        for c in range(len(chapter_titles_auto)):
            print(chapter_titles_auto[c])
            if sep_section:
                for s in range(len(sec_title_list_auto[c])):
                    print(sec_title_list_auto[c][s])
        print('=====')
    all_texts = []
    all_basenames = []
    all_titles = []
    all_nestings = []
    for c in range(len(chapters)):
        all_texts.append(chapters[c])
        all_basenames.append(chapter_basenames[c])
        all_titles.append(chapter_titles[c])
        all_nestings.append(0)
        for s in range(len(sec_list[c])):
            all_texts.append(sec_list[c][s])
            all_basenames.append(sec_basename_list[c][s])
            all_titles.append(sec_title_list[c][s])
            all_nestings.append(1)
    all_suffix = identify_format(all_texts)
    all_fnames = [(b + s) for (b, s) in zip(all_basenames, all_suffix)]
    all_markings = list(map((lambda x: ('!split\n<!-- jupyter-book %s -->\n' % x)), all_fnames))
    all_texts = [(m + t) for (m, t) in zip(all_markings, all_texts)]
    filestr = .join(all_texts)
    (filestr_md, bg_session) = doconce2format(filestr, 'pandoc')
    (filestr_ipynb, bg_session) = doconce2format(filestr, 'ipynb')
    all_texts_md = split_file(filestr_md, '<!-- !split -->\n<!-- jupyter-book .* -->\n')
    all_texts_ipynb = split_ipynb(filestr_ipynb, all_fnames)
    if (len(all_texts_md) != len(all_texts_ipynb)):
        errwarn('*** error : the lengths of .md and .ipynb files should be the same')
        _abort()
    all_texts_formatted = ([[]] * len(all_fnames))
    for i in range(len(all_fnames)):
        all_texts_formatted[i] = all_texts_md[i]
        if all_fnames[i].endswith('.ipynb'):
            all_texts_formatted[i] = all_texts_ipynb[i]
    all_texts_formatted = resolve_links_destinations(all_texts_formatted, all_basenames)
    all_texts_formatted = [fix_media_src(t, , dest) for t in all_texts_formatted]
    for i in range(len(all_texts_formatted)):
        write_file(all_texts_formatted[i], (dest + all_fnames[i]), _encoding=globals.encoding)
    yml_text = create_toc_yml(all_basenames, titles=all_titles, nesting_levels=all_nestings, dest=dest, dest_toc=dest_toc)
    write_file(yml_text, (dest_toc + '_toc.yml'), _encoding=globals.encoding)
    print(('\nWrote _toc.yml and %d chapter files to these folders:\n  %s\n  %s' % (len(all_fnames), os.path.realpath(dest_toc), os.path.realpath(dest))))