MarkdownTranslationSegmenter

Segments markdown into translatable and non-translatable blocks, translates the text portions, and reassembles valid markdown.

Preserves:

  • Fenced code blocks (``` or ~~~)

  • Indented code blocks (4+ spaces or tab)

  • Link URLs and image paths (translates link text only)

  • HTML tags

  • Frontmatter (--- delimited YAML)

Translates:

  • Paragraphs, headings, list items, blockquotes, table cell text

Functions

Link copied to clipboard
suspend fun translateMarkdown(markdown: String, translate: suspend (String) -> String): String

Translate markdown content by extracting text segments, translating them, and reassembling.