apps-script-utils 2.1.1 Help

convertRichTextToMarkdown

function convertRichTextToMarkdown(runs: RichTextRun[], theme: Theme = {}): string;

The inverse of convertMarkdownToRichText: bold, italic and strikethrough become their markers again, a run carrying a link becomes [text](url), and a run set in the theme's code font becomes a code span.

A code run carries no flag of its own — it is recognised by its font — so pass the same theme both ways and the pair round-trips. Runs are written one after another in the order given, without merging neighbours that share a style, so deeply nested formatting may come back expressed differently while reading the same.

Parameters

Parameter

Type

Description

runs

RichTextRun[]

The runs to convert. An empty array gives an empty string.

theme (optional) = {}

Theme

The theme the runs were styled with. Only the code font is read from it.

Returns

string — the Markdown representing the runs.

Throws

Exception

Condition

IllegalArgumentException

no argument is passed, the value is not an array, or an element is not a run with text.

Examples

Back to Markdown

const runs = convertMarkdownToRichText("**bold** and `code`"); convertRichTextToMarkdown(runs); // => "**bold** and `code`"
convertRichTextToMarkdown([ { text: "site", style: { bold: true, link: { url: "https://example.com" } } } ]); // => "[**site**](https://example.com)"

See also

Source

src/appsscript/slide/convertRichTextToMarkdown.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.