/rdfa-parser

A parser for RDFa

Primary LanguageJavaScript

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 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.

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.