code: def get_markdown_doc(
      folder,
      op_name=None,
      domain=None,
      version="last",
      clean=True,
      diff=False,
      example=False,
  ):
      """
      Returns a documentation in Markdown format
      for all :class:`OnnxOperator`.
  
      :param op_name: operator name of None for all
      :param domain: domain
      :param version: version, None for all, `'last'` for the most recent one
      :param clean: clean empty lines
      :param diff: highlights differences between two versions
      :param example: add example to the documentation
      :return: string
      """
      schemas = get_operator_schemas(
          op_name, domain=domain, version=version
      )
  
      def format_name_with_domain(sch):
          if version == "last":
              if sch.domain:
                  return f"{sch.name} ({sch.domain})"
              return sch.name
          if sch.domain:
              return f"{sch.name} - {sch.since_version} ({sch.domain})"
          return f"{sch.name} - {sch.since_version}"
  
      def format_option(obj):
          opts = []
          if OpSchema.FormalParameterOption.Optional == obj.option:
              opts.append("optional")
          elif OpSchema.FormalParameterOption.Variadic == obj.option:
              opts.append("variadic")
          if getattr(obj, "is_homogeneous", False):
              opts.append("heterogeneous")
          if opts:
              return f" ({', '.join(opts)})"
          return ""
  
      def format_example(code):
          return code
  
      def get_constraint(const, ii):
          if const.type_param_str:
              name = const.type_param_str
          else:
              name = str(ii)
          name = f"**{name}** in ("
          if const.allowed_type_strs:
              types = [
                  f"`{type_str}`"
                  for type_str in sorted(const.allowed_type_strs)
              ]
              text = ", ".join(types)
              name += " " + text + " )"
          return name
  
      def getname(obj, i):
          name = obj.name
          if len(name) == 0:
              return str(i)
          return name
  
      def process_documentation(doc):
          if doc is None:
              doc = ""
          if not isinstance(doc, str):
              raise TypeError(
                  f"doc must be a string not {type(doc)!r} - {doc + 42!r}."
              )
          main_docs_url = "https://github.com/onnx/onnx/blob/main/"
          rep = {
              "[the doc](IR.md)": f"[ONNX IR]({main_docs_url}docs/IR.md)",
              "[the doc](Broadcasting.md)": f"[Broadcasting in ONNX]({main_docs_url}docs/Broadcasting.md)",
          }
          for key, value in rep.items():
              doc = doc.replace(key, value)
          return textwrap.dedent(doc)
  
      def build_doc_url(sch):
          doc_url = (
              "https://github.com/onnx/onnx/blob/main/docs/Operators"
          )
          if "ml" in sch.domain:
              doc_url += "-ml"
          doc_url += ".md"
          doc_url += "#"
          if sch.domain not in (None, "", "ai.onnx"):
              doc_url += sch.domain + "."
          return doc_url
  
      def format_default_value(value):
          if isinstance(value, float):
              formatted = str(np.round(value, 5))
              # use default formatting, unless too long.
              if len(formatted) > 10:
                  formatted = f"({value:e})"
              return formatted
          if isinstance(value, (bytes, bytearray)):
              return value.decode("utf-8")
          return str(value)
  
      def clean_default_value(attr):
          if not attr.default_value.name:
              return ""
          default_value = onnx.helper.get_attribute_value(
              attr.default_value
          )
          if isinstance(default_value, onnx.AttributeProto) and hasattr(
              default_value, "default_value"
          ):
              if attr.type in _attribute_conversion_functions:
                  sval = _attribute_conversion_functions[attr.type](
                      default_value
                  )
                  return f"(default is `{sval!r}`)"
  
          if isinstance(default_value, list):
              sval = [
                  format_default_value(val) for val in default_value
              ]
          else:
              sval = format_default_value(default_value)
          return f"(default is `{sval!r}`)"
  
      def text_wrap(text, indent):
          s = " " * indent
          lines = textwrap.wrap(
              text, initial_indent=s, subsequent_indent=s
          )
          return "\n".join(lines)
  
      examples = get_onnx_example(op_name, domain) if example else {}
      docs = _template_operator.render(
          schemas=schemas,
          OpSchema=OpSchema,
          len=len,
          getattr=getattr,
          sorted=sorted,
          format_option=format_option,
          get_constraint=get_constraint,
          getname=getname,
          enumerate=enumerate,
          format_name_with_domain=format_name_with_domain,
          process_documentation=process_documentation,
          build_doc_url=build_doc_url,
          text_wrap=text_wrap,
          str=str,
          clean_default_value=clean_default_value,
          examples=examples,
          format_example=format_example,
          is_last_schema=is_last_schema,
      )
  
      d_links = {}
      for schema in schemas:
          sdom = schema.domain.replace(".", "-")
          d_links[
              schema.since_version
          ] = f"l-onnx-op{sdom}-{schema.name.lower()}-{schema.since_version}"
  
      if diff:
          lines = docs.split("\n")
          new_lines = [""]
          for line in lines:
              line = line.rstrip("\r\t ")
              if len(line) == 0 and len(new_lines[-1]) == 0:
                  continue
              new_lines.append(line)
          docs = "\n".join(new_lines)
          docs, d_links_diff = _insert_diff(
              folder,
              docs,
              ".. tag-diff-insert.",
              op_name=op_name,
              version=version,
              domain=domain,
          )
          d_links.update(d_links_diff)
  
      if clean:
          lines = docs.split("\n")
          new_lines = [""]
          for line in lines:
              line = line.rstrip("\r\t ")
              if len(line) == 0 and len(new_lines[-1]) == 0:
                  continue
              new_lines.append(line)
          docs = "\n".join(new_lines)
  
      return docs, d_links, len(examples)
  
imports: import difflib
  import importlib
  import inspect
  import keyword
  import os
  import pathlib
  import re
  import shutil
  import sys
  import textwrap
  from typing import Any
  import jinja2
  import numpy
  from sphinx.util import logging
  import onnx
  from onnx.backend.test.case.base import _Exporter
  from onnx.defs import OpSchema
label_desc: Use image node_id 8 for calling a global function with example usage: get_markdown_doc(folder, op_name, domain, version, clean, diff, example) and returns: docs,  d_links,  len, sch, str, sch, str, code, name, name, textwrap, doc_url, str, str, sval, str, str, sch, sch, str, sch, str, sch, str, str, str, str, str, formatted, value, str, sch, str, sch, str, str, sval, str