What Tools or Scripts Can I Use to Convert Markdown from ChatGPT Output into a Google Docs Format?

This topic was automatically generated from Slack. You can find the original thread here.

Are there any good scripts or tools I can use to convert Markdown so it looks good in Google Docs.
ChatGPT creates markdown as an output and I want to convert this to a nice looking document using the chatGPT functions.

the chatgpt.com can do it… but appears to be elusive in the API assistant area… any clues welcome as I am totally stuck!

I created some code. It is not perfect, but might help others till we can have the marked or other functions in pipedream that do it more eloquently

import { axios } from “@pipedream/platform”;

export default defineComponent({
props: {
google_docs: {
type: “app”,
app: “google_docs”,
},
documentId: {
type: “string”,
label: “Document ID”,
},
markdownContent: {
type: “string”,
label: “Markdown Content”,
},
},
async run({ steps, $ }) {
const markdownContent = this.markdownContent;
const lines = markdownContent.split(“\n”);
const requests = ;
let currentIndex = 1;

for (const line of lines) {
  if (line.startsWith("# ")) {
    const text = line.substring(2) + "\n";
    if (text.trim().length > 0) {
      requests.push({
        insertText: {
          location: {
            index: currentIndex,
          },
          text: text,
        },
      });
      requests.push({
        updateTextStyle: {
          range: {
            startIndex: currentIndex,
            endIndex: currentIndex + text.length - 1,
          },
          textStyle: {
            bold: true,
            fontSize: {
              magnitude: 24,
              unit: 'PT',
            },
          },
          fields: "bold,fontSize",
        },
      });
      currentIndex += text.length;
    }
  } else if (line.startsWith("## ")) {
    const text = line.substring(3) + "\n";
    if (text.trim().length > 0) {
      requests.push({
        insertText: {
          location: {
            index: currentIndex,
          },
          text: text,
        },
      });
      requests.push({
        updateTextStyle: {
          range: {
            startIndex: currentIndex,
            endIndex: currentIndex + text.length - 1,
          },
          textStyle: {
            bold: true,
            fontSize: {
              magnitude: 18,
              unit: 'PT',
            },
          },
          fields: "bold,fontSize",
        },
      });
      currentIndex += text.length;
    }
  } else if (line.startsWith("### ")) {
    const text = line.substring(4) + "\n";
    if (text.trim().length > 0) {
      requests.push({
        insertText: {
          location: {
            index: currentIndex,
          },
          text: text,
        },
      });
      requests.push({
        updateTextStyle: {
          range: {
            startIndex: currentIndex,
            endIndex: currentIndex + text.length - 1,
          },
          textStyle: {
            bold: true,
            fontSize: {
              magnitude: 14,
              unit: 'PT',
            },
          },
          fields: "bold,fontSize",
        },
      });
      currentIndex += text.length;
    }
  } else if (line.startsWith("---")) {
    const text = line + "\n";
    requests.push({
      insertText: {
        location: {
          index: currentIndex,
        },
        text: text,
      },
    });
    currentIndex += text.length;
  } else if (line.startsWith("- ")) {
    const text = line.substring(2) + "\n";
    if (text.trim().length > 0) {
      requests.push({
        insertText: {
          location: {
            index: currentIndex,
          },
          text: text,
        },
      });
      requests.push({
        createParagraphBullets: {
          range: {
            startIndex: currentIndex,
            endIndex: currentIndex + text.length,
          },
          bulletPreset: "BULLET_DISC_CIRCLE_SQUARE",
        },
      });
      currentIndex += text.length;
    }
  } else {
    const parts = line.split(/(\**\**.**?\**\**|\**.**?\**|__.**?__|_.**?_)/);
    for (const part of parts) {
      if ((part.startsWith("****") && part.endsWith("****")) || (part.startsWith("__") && part.endsWith("__"))) {
        const text = part.substring(2, part.length - 2);
        if (text.length > 0) {
          requests.push({
            insertText: {
              location: {
                index: currentIndex,
              },
              text: text,
            },
          });
          requests.push({
            updateTextStyle: {
              range: {
                startIndex: currentIndex,
                endIndex: currentIndex + text.length,
              },
              textStyle: {
                bold: true,
              },
              fields: "bold",
            },
          });
          currentIndex += text.length;
        }
      } else if ((part.startsWith("**") && part.endsWith("**")) || (part.startsWith("_") && part.endsWith("_"))) {
        const text = part.substring(1, part.length - 1);
        if (text.length > 0) {
          requests.push({
            insertText: {
              location: {
                index: currentIndex,
              },
              text: text,
            },
          });
          requests.push({
            updateTextStyle: {
              range: {
                startIndex: currentIndex,
                endIndex: currentIndex + text.length,
              },
              textStyle: {
                italic: true,
              },
              fields: "italic",
            },
          });
          currentIndex += text.length;
        }
      } else {
        if (part.length > 0) {
          requests.push({
            insertText: {
              location: {
                index: currentIndex,
              },
              text: part,
            },
          });
          currentIndex += part.length;
        }
      }
    }
    requests.push({
      insertText: {
        location: {
          index: currentIndex,
        },
        text: "\n",
      },
    });
    currentIndex += 1;
  }
}

try {
  const batchUpdateResponse = await axios($, {
    method: "POST",
    url: `https://docs.googleapis.com/v1/documents/${this.documentId}:batchUpdate`,
    headers: {
      Authorization: `Bearer ${this.google_docs.$auth.oauth_access_token}`,
      "Content-Type": "application/json",
    },
    data: {
      requests: requests,
    },
  });

  return batchUpdateResponse.data;
} catch (error) {
  $.export("error", error);
  throw new Error(`Failed to update the document: ${error.message}`);
}

},
});