{"version":3,"file":"markdown.cjs","sources":["../../../src/text/markdown.ts"],"sourcesContent":["import { marked, MarkedOptions } from 'marked';\nimport { mangle } from 'marked-mangle';\n\nimport { sanitizeTextPanelContent } from './sanitize';\n\nlet hasInitialized = false;\n\nexport interface RenderMarkdownOptions {\n  noSanitize?: boolean;\n  breaks?: boolean;\n}\n\nconst markdownOptions: MarkedOptions = {\n  pedantic: false,\n  gfm: true,\n  breaks: false,\n};\n\nexport function renderMarkdown(str?: string, options?: RenderMarkdownOptions): string {\n  if (!hasInitialized) {\n    marked.use(mangle());\n    marked.setOptions({ ...markdownOptions });\n    hasInitialized = true;\n  }\n\n  let opts = undefined;\n  if (options?.breaks) {\n    opts = {\n      ...markdownOptions,\n      breaks: true,\n    };\n  }\n  const html = marked(str || '', opts);\n\n  // `marked()` returns a promise if using any extensions that require async processing.\n  // we don't use any async extensions, but there is no way for typescript to know this, so we need to check the type.\n  if (typeof html !== 'string') {\n    throw new Error('Failed to process markdown synchronously.');\n  }\n\n  if (options?.noSanitize) {\n    return html;\n  }\n\n  return sanitizeTextPanelContent(html);\n}\n\nexport function renderTextPanelMarkdown(str?: string, options?: RenderMarkdownOptions): string {\n  if (!hasInitialized) {\n    marked.use(mangle());\n    marked.setOptions({ ...markdownOptions });\n    hasInitialized = true;\n  }\n\n  const html = marked(str || '');\n\n  // `marked()` returns a promise if using any extensions that require async processing.\n  // we don't use any async extensions, but there is no way for typescript to know this, so we need to check the type.\n  if (typeof html !== 'string') {\n    throw new Error('Failed to process markdown synchronously.');\n  }\n\n  if (options?.noSanitize) {\n    return html;\n  }\n\n  return sanitizeTextPanelContent(html);\n}\n"],"names":["marked","mangle","sanitizeTextPanelContent"],"mappings":";;;;;;;;;AAKA,IAAI,cAAA,GAAiB,KAAA;AAOrB,MAAM,eAAA,GAAiC;AAAA,EACrC,QAAA,EAAU,KAAA;AAAA,EACV,GAAA,EAAK,IAAA;AAAA,EACL,MAAA,EAAQ;AACV,CAAA;AAEO,SAAS,cAAA,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