From dab5454a5440e057e515887d8eeedea0a876dfc9 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Mon, 15 Jul 2024 15:57:26 +0200 Subject: [PATCH] feat: RDFa --- .changeset/nice-bats-lay.md | 5 +++ package-lock.json | 84 ++++++++++++++++++++++++++++++++++++- package.json | 2 + src/index.js | 1 + src/lib/RdfConverter.js | 12 +++--- src/lib/parsers/rdfa.js | 10 +++++ 6 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 .changeset/nice-bats-lay.md create mode 100644 src/lib/parsers/rdfa.js diff --git a/.changeset/nice-bats-lay.md b/.changeset/nice-bats-lay.md new file mode 100644 index 0000000..f674e6f --- /dev/null +++ b/.changeset/nice-bats-lay.md @@ -0,0 +1,5 @@ +--- +"@zazuko/rdf-converter": patch +--- + +Added RDFa parser diff --git a/package-lock.json b/package-lock.json index 732f02a..eb65cfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,11 +16,13 @@ "@rdfjs-elements/rdf-snippet": "^0.4.3", "@rdfjs/term-set": "^2.0.1", "@vaadin/vaadin": "^22", + "@zazuko/formats-lazy": "^1.0.1", "@zazuko/rdf-vocabularies": ">=2021", "clipboard-copy": "^4.0.1", "http-media-type": "^1.3.2", "lit": "^2", "lit-vaadin-helpers": "^0.3.1", + "rdfa-streaming-parser": "^2.0.1", "tbbt-ld": "^1.1.0" }, "devDependencies": { @@ -5303,7 +5305,6 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", - "dev": true, "funding": [ { "type": "github", @@ -9946,6 +9947,87 @@ "resolved": "https://registry.npmjs.org/rdf-normalize/-/rdf-normalize-1.0.0.tgz", "integrity": "sha512-1ocjoxovKc4+AyS4Tgtroay5R33yrtM2kQnAGvVaB0iGSRggukHxMJW0y8xTR7TwKZabS+7oMSQNMdbu/qTtCQ==" }, + "node_modules/rdfa-streaming-parser": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/rdfa-streaming-parser/-/rdfa-streaming-parser-2.0.1.tgz", + "integrity": "sha512-7Yyaj030LO7iQ38Wh/RNLVeYrVFJeyx3dpCK7C1nvX55eIN/gE4HWfbg4BYI9X7Bd+eUIUMVeiKYLmYjV6apow==", + "dependencies": { + "@rdfjs/types": "*", + "htmlparser2": "^8.0.0", + "rdf-data-factory": "^1.1.0", + "readable-stream": "^4.0.0", + "relative-to-absolute-iri": "^1.0.2" + } + }, + "node_modules/rdfa-streaming-parser/node_modules/dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + }, + "funding": { + "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" + } + }, + "node_modules/rdfa-streaming-parser/node_modules/domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "dependencies": { + "domelementtype": "^2.3.0" + }, + "engines": { + "node": ">= 4" + }, + "funding": { + "url": "https://github.com/fb55/domhandler?sponsor=1" + } + }, + "node_modules/rdfa-streaming-parser/node_modules/domutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz", + "integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==", + "dependencies": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3" + }, + "funding": { + "url": "https://github.com/fb55/domutils?sponsor=1" + } + }, + "node_modules/rdfa-streaming-parser/node_modules/entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/rdfa-streaming-parser/node_modules/htmlparser2": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.2.tgz", + "integrity": "sha512-GYdjWKDkbRLkZ5geuHs5NY1puJ+PXwP7+fHPRz06Eirsb9ugf6d8kkXav6ADhcODhFFPMIXyxkxSuMf3D6NCFA==", + "funding": [ + "https://github.com/fb55/htmlparser2?sponsor=1", + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1", + "entities": "^4.4.0" + } + }, "node_modules/rdfxml-streaming-parser": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/rdfxml-streaming-parser/-/rdfxml-streaming-parser-2.4.0.tgz", diff --git a/package.json b/package.json index 9f43a6a..fb3bd34 100644 --- a/package.json +++ b/package.json @@ -21,11 +21,13 @@ "@rdfjs-elements/rdf-snippet": "^0.4.3", "@rdfjs/term-set": "^2.0.1", "@vaadin/vaadin": "^22", + "@zazuko/formats-lazy": "^1.0.1", "@zazuko/rdf-vocabularies": ">=2021", "clipboard-copy": "^4.0.1", "http-media-type": "^1.3.2", "lit": "^2", "lit-vaadin-helpers": "^0.3.1", + "rdfa-streaming-parser": "^2.0.1", "tbbt-ld": "^1.1.0" }, "devDependencies": { diff --git a/src/index.js b/src/index.js index d2e4d8b..64e0a4e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +import "./lib/parsers/rdfa.js"; import { RdfConverter } from "./lib/RdfConverter.js"; customElements.define("rdf-converter", RdfConverter); diff --git a/src/lib/RdfConverter.js b/src/lib/RdfConverter.js index faa3286..c4f290e 100644 --- a/src/lib/RdfConverter.js +++ b/src/lib/RdfConverter.js @@ -1,4 +1,10 @@ import { css, html, LitElement, render } from "lit"; +import TermSet from "@rdfjs/term-set"; +import copy from "clipboard-copy"; +import { InputController } from "./InputController.js"; +import { OutputController } from "./OutputController.js"; +import { extractPrefix } from "./prefixes.js"; +import Package from "../../package.json"; import "@vaadin/vaadin-app-layout/vaadin-app-layout.js"; import "@vaadin/vaadin-split-layout/vaadin-split-layout.js"; import "@rdfjs-elements/rdf-editor/rdf-editor.js"; @@ -7,12 +13,6 @@ import "@vaadin/vaadin-app-layout/vaadin-drawer-toggle.js"; import "@vaadin/vaadin-form-layout/vaadin-form-layout.js"; import "@vaadin/vaadin-lumo-styles/typography"; import "@vaadin/vaadin-button/vaadin-button.js"; -import TermSet from "@rdfjs/term-set"; -import copy from "clipboard-copy"; -import { InputController } from "./InputController.js"; -import { OutputController } from "./OutputController.js"; -import { extractPrefix } from "./prefixes.js"; -import Package from "../../package.json"; export class RdfConverter extends LitElement { static get styles() { diff --git a/src/lib/parsers/rdfa.js b/src/lib/parsers/rdfa.js new file mode 100644 index 0000000..a3ed656 --- /dev/null +++ b/src/lib/parsers/rdfa.js @@ -0,0 +1,10 @@ +import { lazySink } from "@zazuko/formats-lazy/LazySink.js"; +import formats from "@rdfjs-elements/formats-pretty"; + +formats.parsers.set( + "text/html", + new (lazySink(async () => { + const { RdfaParser } = await import("rdfa-streaming-parser"); + return RdfaParser; + }))({ contentType: "text/html" }) +);