An RDFa parser in JS. Not yet complete but we aim for full support of HTML+RDFa 1.1.
rdfa-parser provides functions to parse either HTMLElements or Strings containg RDFa. A callback
function is invoked whenever a quad has been read. The argument passed to this function is an rdfjs compliant quad.
Parses a Node / HTMLElement with RDFa.
Parses a String containing a Node / HTMLElement with RDFa
Parameter | Type | Description | Default |
---|---|---|---|
element | Node | Node / Element to be parsed | Required Parameter |
string | String | String of Node / Element to be parsed | Required Parameter |
callback | Function | Function to give a quad. Gets called every time a quad is found | Required Parameter |
base | IRI | baseIRI to be used | element.baseURI || window.location.href |
useInitialContext | boolean | If https://www.w3.org/2013/json-ld-context/rdfa11 should be loaded as initial set of prefixes | false |
Run yarn build
to create /distribution/latest/rdfa.js
for use in websites.
<head>
...
<script src="/distribution/latest/rdfa.js"></script>
<script type="text/javascript" src="https://retog.github.io/ext-rdflib/latest/rdf.js"></script>
<script>
window.onload = () => {
let g = $rdf.graph();
RDFa.parseDOM(document.documentElement, (quad) => g.add(quad));
const output = $rdf.serializers["text/turtle"].import(g.toStream());
output.on('data', ntriples => console.log(ntriples.toString()));
}
</script>
...
</head>
All Triples found will be console.log
ed as stringified ntriples.