A parser for RDFa
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
examples
src
test
.gitignore
.npmignore
.travis.yml
.travis_publish
README.md
package.json
webpack.config.js
yarn.lock

README.md

rdfa-parser

Build Status

An RDFa parser in JS. Not yet complete but we aim for full support of HTML+RDFa 1.1.

Usage

rdfa-parser provides functions to parse HTMLElements and Strings. The call a callback function which is invoked with an rdfjs compliant quad.

parseDOM(element,callback,base,useInitialContext)

Parses a Node / HTMLElement with RDFa.

parseString(string,callback,base,useInitialContext)

Parses a String containing a Node / HTMLElement with RDFa

Parameters

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

Building

Run yarn build to create /distribution/latest/rdfa.js for use in websites.

Example 1

<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.loged as stringified ntriples.