Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including ld2h with all npm packages installed. Try it out:

var ld2h = require("ld2h")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ld2h v2.3.3

Expand tags by rendering local or remote RDF resources, recursively.

LD2h Build Status

Expand tags by rendering local or remote RDF resources, recursively.

To see it in action check out

Include the required scripts

<script src="//"></script>
<script src="dist/ld2h.js"></script>

The above includes the parser for text/turtle to support more formats you'll have to include the respective parsers.

Link a matcher file

<link rel="matchers" href="example-renderers.ttl" type="text/turtle" />

alternatively you can also define the matchers inline in a script element with id matchers:

    <script id="matchers" type="text/turtle">
        @prefix rdf: <> .


To learn how to define matchers check out the rdf2h documentation:

Include some data

This is not needed if you only want to render fetched remote resources.

<script id="data" type="text/turtle">
    @prefix s: <>.
    @prefix foaf: <> .

    <> s:headline "An LD2h demo page" .
    <> s:text '''Everything you see on this page is content expressed in RDF either within this
page or from somewhere else on the web rendered  in the browser using 
<a href="">RDF2h</a> and mustache templates.'''.

Render resources

Wherever you want a resource from the included RDF graph to be rendered give the tag a resource attribute and specify render as class. The following causes the whole HTML document to be replaced with the result of rendering the resource with the URI of the page as HTML:

<html class="render" resource="">

You can also specify a context using the context attribute:

<select  class="render" resource="" context="c:options">
    <option>This will be replaced with the persons....</option>

Fetch resources

LD2h can retrieve RDF descriptions from the web and render the result, for example you can the following tag to your HTML:

<span resource="" class="fetch">TimBL from remote RDF should appear here</span>

Fetch resource from alternative location

By default LD2h dereferences the URI of the resource to get its description, in some situations the RDF description should be retrieved from a different location. This can be achieved by specifying the graph attribute, for example:

<span resource="" 
          graph="" class="fetch">schema:BusOrCoach with data from ontology on GitHub</span>

Start the process

Start LD2h expansion adding the following code:

<script type="text/javascript">
    $(function () {


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free