:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table'
import { MarkdownManager } from '@tiptap/markdown'
import StarterKit from '@tiptap/starter-kit'
import { JSONContent } from 'lib/components/RichContentEditor/types'
import { expandFlattenedMarkdownTables } from 'lib/utils/markdown'
const markdownManager = new MarkdownManager({
extensions: [StarterKit, Table, TableRow, TableHeader, TableCell],
})
/**
* Convert markdown string to tiptap JSONContent array using TipTap's official markdown parser.
*/
export function markdownToTiptap(markdown: string): JSONContent[] {
if (!markdown || markdown.trim() === '') {
return []
}
const doc = markdownManager.parse(expandFlattenedMarkdownTables(markdown))
// The parser returns a doc node with content array, we want just the content
return (doc.content as JSONContent[]) || []
}