code: def writes(
      notebook, fmt, version=nbformat.NO_CONVERT, config=None, **kwargs
  ):
      """Return the text representation of the notebook
  
      :param notebook: the notebook
      :param fmt: the jupytext format like `md`, `py:percent`, ...
      :param version: see nbformat.writes
      :param config: (optional) a Jupytext configuration object
      :param kwargs: (not used) additional parameters for nbformat.writes
      :return: the text representation of the notebook
      """
      if version is not nbformat.NO_CONVERT:
          if not isinstance(version, int):
              raise TypeError(
                  "The argument 'version' should be either nbformat.NO_CONVERT, or an integer."
              )
          notebook = nbformat.convert(notebook, version)
      (version, version_minor) = nbformat.reader.get_version(notebook)
      if version < 4:
          raise NotSupportedNBFormatVersion(
              f"Notebooks in nbformat version {version}.{version_minor} are not supported by Jupytext. "
              f"Please convert your notebooks to nbformat version 4 with "
              f"'jupyter nbconvert --to notebook --inplace', or call this function with 'version=4'."
          )
      if version > 4 or (version == 4 and version_minor > 5):
          warnings.warn(
              f"Notebooks in nbformat version {version}.{version_minor} "
              f"have not been tested with Jupytext version {__version__}."
          )
  
      metadata = deepcopy(notebook.metadata)
      rearrange_jupytext_metadata(metadata)
      fmt = copy(fmt)
      fmt = long_form_one_format(fmt, metadata)
      ext = fmt["extension"]
      format_name = fmt.get("format_name")
  
      if ext == ".ipynb":
          return nbformat.writes(
              drop_text_representation_metadata(notebook, metadata),
              version,
              **kwargs,
          )
  
      if not format_name:
          format_name = format_name_for_ext(
              metadata, ext, explicit_default=False
          )
  
      if format_name:
          fmt["format_name"] = format_name
          update_jupytext_formats_metadata(metadata, fmt)
  
      writer = TextNotebookConverter(fmt, config)
      return writer.writes(notebook, metadata)
  
imports: import logging
  import os
  import sys
  import warnings
  from copy import copy, deepcopy
  import nbformat
  from nbformat.v4.nbbase import NotebookNode, new_code_cell, new_notebook
  from nbformat.v4.rwbase import NotebookReader, NotebookWriter
  from .cell_metadata import _IGNORE_CELL_METADATA
  from .formats import _VALID_FORMAT_OPTIONS, divine_format, format_name_for_ext, get_format_implementation, guess_format, long_form_one_format, read_format_from_metadata, rearrange_jupytext_metadata, update_jupytext_formats_metadata
  from .header import encoding_and_executable, header_to_metadata_and_cell, insert_jupytext_info_and_filter_metadata, insert_or_test_version_number, metadata_and_cell_to_header
  from .languages import default_language_from_metadata_and_ext, set_main_and_cell_language
  from .metadata_filter import filter_metadata, update_metadata_filters
  from .myst import MYST_FORMAT_NAME, myst_extensions, myst_to_notebook, notebook_to_myst
  from .pandoc import md_to_notebook, notebook_to_md
  from .pep8 import pep8_lines_between_cells
  from .quarto import notebook_to_qmd, qmd_to_notebook
  from .version import __version__
label_desc: Use image node_id 3 for calling a global function with example usage: writes(notebook, fmt, version, config) and returns: writer, nbformat