Spaces:
Sleeping
Sleeping
Download apps/api/src/scraper/scrapeURL/engines/pdf/markdownToHtml.ts from s-eto-hub/firecrawl-api: direct link, hf CLI and curl.
- Browser
- Download file 620 Bytes
-
https://huggingface.co/spaces/s-eto-hub/firecrawl-api/resolve/main/apps/api/src/scraper/scrapeURL/engines/pdf/markdownToHtml.ts
- Command line
-
hf download hf://spaces/s-eto-hub/firecrawl-api/apps/api/src/scraper/scrapeURL/engines/pdf/markdownToHtml.ts
-
curl -L -o markdownToHtml.ts https://huggingface.co/spaces/s-eto-hub/firecrawl-api/resolve/main/apps/api/src/scraper/scrapeURL/engines/pdf/markdownToHtml.ts
620 Bytes
| 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, "&") | |
| .replace(/</g, "<") | |
| .replace(/>/g, ">") | |
| .replace(/"/g, """) | |
| .replace(/'/g, "'")}</pre>`; | |
| } | |
| } | |