Created
January 29, 2025 13:42
-
-
Save EpicKiwi/30c86c28fc0c9a8a0b3a7c14100e13c3 to your computer and use it in GitHub Desktop.
Parse RDFa from HTML in Deno
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import jsonld from "https://esm.sh/jsonld?target=esnext" | |
| import jsonldRdfaParser from "https://esm.sh/jsonld8-rdfa-parser?target=esnext" | |
| import { DOMParser, Node } from "https://esm.sh/linkedom?target=esnext"; | |
| import * as path from "jsr:@std/path" | |
| //@ts-ignore | |
| Node.prototype.getAttributeNodeNS = function(_, attr){ return this.getAttributeNode(attr) } | |
| jsonld.registerRDFParser('text/html', jsonldRdfaParser); | |
| const filePath = "index.html" | |
| const document = parser.parseFromString(await Deno.readTextFile(filePath), "text/html") | |
| const base = document.createElement("base") | |
| base.setAttribute("href", path.toFileUrl(path.resolve(filePath))) | |
| document.head.append(base) | |
| const json = await jsonld.fromRDF(document.documentElement, {format: 'text/html'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment