Spaces:
Runtime error
Runtime error
Download api/src/utils/scrape/plugins/highlightedCodeBlock.ts from supernovagateway/Steel: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/supernovagateway/Steel/resolve/main/api/src/utils/scrape/plugins/highlightedCodeBlock.ts
- Command line
-
hf download hf://spaces/supernovagateway/Steel/api/src/utils/scrape/plugins/highlightedCodeBlock.ts
-
curl -L -o highlightedCodeBlock.ts https://huggingface.co/spaces/supernovagateway/Steel/resolve/main/api/src/utils/scrape/plugins/highlightedCodeBlock.ts
1.03 kB
| // Adapted from https://github.com/laurent22/joplin/blob/dev/packages/turndown-plugin-gfm/src/tables.js | |
| import TurndownService from "@joplin/turndown"; | |
| const highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/; | |
| export default function highlightedCodeBlock(turndownService: TurndownService) { | |
| turndownService.addRule("highlightedCodeBlock", { | |
| filter: function (node) { | |
| const firstChild = node.firstChild as HTMLElement; | |
| return ( | |
| node.nodeName === "DIV" && | |
| highlightRegExp.test(node.className) && | |
| firstChild && | |
| firstChild.nodeName === "PRE" | |
| ); | |
| }, | |
| replacement: function (content, node, options) { | |
| const className = (node as HTMLElement).className || ""; | |
| const language = (className.match(highlightRegExp) || [null, ""])[1]; | |
| return ( | |
| "\n\n" + | |
| options.fence + | |
| language + | |
| "\n" + | |
| (node.firstChild as HTMLElement).textContent + | |
| "\n" + | |
| options.fence + | |
| "\n\n" | |
| ); | |
| }, | |
| }); | |
| } | |