TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Shacled Turtle 🐢

A Code Mirror 6 Turtle language support that provides autocompletion based on the content of a schema graph. Schemas can be written by using either RDFS, SHACL or a mix of both (= your usual ontology and validation RDF graphs).

How to use

You can use this extension like any other Code Mirror 6 extension.

For example, by using parcel:

  • Start a new project: npm init

  • Install the dependencies: npm install @codemirror/basic-setup @codemirror/state @codemirror/view shacled-turtle n3

  • Install parcel and n3 types npm install --save-dev parcel @types/n3

  • Make a file named index.ts with the following content:

import { basicSetup } from "@codemirror/basic-setup";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { shacledTurtle, changeSchema } from "shacled-turtle";
import * as n3 from "n3";

const prefixes = 
`@prefix rdf: <> .
@prefix rdfs: <> .
@prefix sh: <> .
@prefix xsd: <> .
@prefix owl: <> .
@prefix ex: <> .
@prefix s: <> .`;

// Build a CodeMirror editor with the Shacled Turtle extension
const editor = new EditorView({
  parent: document.getElementById("editorparent")!,
  state: EditorState.create({
    doc: prefixes + "\n\n\n\n\n",
    extensions: [basicSetup, shacledTurtle()]

// Write the corresponding schema with SHACL
const shapeGraph = prefixes + `
  ex:PersonShape a sh:NodeShape ;
    sh:targetClass s:Person ;
    sh:property [ sh:path s:name ] .

// Tell the editor that the schema used to provide autocompletion is
// the schema graph described in variable shapeGraph.
changeSchema(editor.state, new n3.Parser().parse(shapeGraph));
  • Make a file named index.html with the following content
    <h1>Shacled Turtle Basic example</h1>
    <div id="editorparent"></div>
    <script src="index.ts" type="module"></script>

On the code editor, type ex:Alice r, the editor suggests rdf:type then s:Person.

After ex:Alice rdf:type s:Person . , write ex:alice s and the engine will suggest s:name because it knows Alice is a person.


Published under either the CeCCIL-B license or the MIT License by INSA Lyon / Julian Bruyat.

Package Sidebar


npm i shacled-turtle

Weekly Downloads






Unpacked Size

151 kB

Total Files


Last publish


  • bruju