Spaces:
Sleeping

File size: 620 Bytes
097eaf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import * as marked from "marked";
import type { Logger } from "winston";

export async function safeMarkdownToHtml(
  markdown: string,
  logger: Logger,
  scrapeId: string,
): Promise<string> {
  try {
    return await marked.parse(markdown, { async: true });
  } catch (e) {
    logger.warn("marked.parse failed, falling back to <pre> wrapper", {
      error: e,
      scrapeId,
      markdownLength: markdown.length,
    });
    return `<pre>${markdown
      .replace(/&/g, "&amp;")
      .replace(/</g, "&lt;")
      .replace(/>/g, "&gt;")
      .replace(/"/g, "&quot;")
      .replace(/'/g, "&#39;")}</pre>`;
  }
}