Skip to content

Commit 555e324

Browse files
Rdf highlighting (#75)
feat: add highlight to turtle syntax
1 parent b8d633a commit 555e324

File tree

8 files changed

+153
-17
lines changed

8 files changed

+153
-17
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
Language: Turtle
3+
Author: Redmer KRONEMEIJER <[email protected]>
4+
Contributors: Mark ELLIS <[email protected]>, Vladimir ALEXIEV <[email protected]>
5+
*/
6+
function hljsDefineTurtle(hljs) {
7+
var KEYWORDS = {
8+
keyword: "BASE|2 PREFIX|5 @base|10 @prefix|10",
9+
literal: "true false",
10+
built_in: "a",
11+
};
12+
13+
var IRI_LITERAL = {
14+
className: "literal",
15+
relevance: 1,
16+
begin: /</,
17+
end: />/,
18+
};
19+
20+
var PN_CHARS_BASE =
21+
"A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF";
22+
var PN_CHARS_U = PN_CHARS_BASE + "_";
23+
var PN_CHARS = "-" + PN_CHARS_U + "0-9\u00B7\u0300-\u036F\u203F-\u2040";
24+
var BLANK_NODE_LABEL =
25+
"_:" + PN_CHARS_U + "0-9?";
26+
var PN_PREFIX =
27+
"" + PN_CHARS_BASE + "?";
28+
var PERCENT = "%[0-9A-Fa-f][0-9A-Fa-f]";
29+
var PN_LOCAL_ESC = "\\\\[_~.!$&'()*+,;=/?#@%-]";
30+
var PLX = PERCENT + "|" + PN_LOCAL_ESC;
31+
var PNAME_NS = "(" + PN_PREFIX + ")?:";
32+
var PN_LOCAL =
33+
"([" +
34+
PN_CHARS_U +
35+
":0-9]|" +
36+
PLX +
37+
")([" +
38+
PN_CHARS +
39+
".:]|" +
40+
PLX +
41+
")*([" +
42+
PN_CHARS +
43+
":]|" +
44+
PLX +
45+
")?";
46+
var PNAME_LN = PNAME_NS + PN_LOCAL;
47+
var PNAME_NS_or_LN = PNAME_NS + "(" + PN_LOCAL + ")?";
48+
49+
var PNAME = {
50+
begin: PNAME_NS_or_LN,
51+
relevance: 0,
52+
className: "symbol",
53+
};
54+
55+
var BLANK_NODE = {
56+
begin: BLANK_NODE_LABEL,
57+
relevance: 10,
58+
className: "template-variable",
59+
};
60+
61+
var LANGTAG = {
62+
begin: /@[a-zA-Z]+([a-zA-Z0-9-]+)*/,
63+
className: "type",
64+
relevance: 0,
65+
};
66+
67+
var DATATYPE = {
68+
begin: "\\^\\^" + PNAME_LN,
69+
className: "type",
70+
relevance: 10,
71+
};
72+
73+
var TRIPLE_APOS_STRING = {
74+
begin: /'''/,
75+
end: /'''/,
76+
className: "string",
77+
relevance: 0,
78+
};
79+
80+
var TRIPLE_QUOTE_STRING = {
81+
begin: /"""/,
82+
end: /"""/,
83+
className: "string",
84+
relevance: 0,
85+
};
86+
87+
var APOS_STRING_LITERAL = JSON.parse(JSON.stringify(hljs.APOS_STRING_MODE));
88+
APOS_STRING_LITERAL.relevance = 0;
89+
90+
var QUOTE_STRING_LITERAL = JSON.parse(JSON.stringify(hljs.QUOTE_STRING_MODE));
91+
QUOTE_STRING_LITERAL.relevance = 0;
92+
93+
return {
94+
name: "Turtle",
95+
case_insensitive: true,
96+
keywords: KEYWORDS,
97+
aliases: ["turtle", "ttl", "n3"],
98+
contains: [
99+
LANGTAG,
100+
DATATYPE,
101+
IRI_LITERAL,
102+
BLANK_NODE,
103+
PNAME,
104+
TRIPLE_APOS_STRING,
105+
TRIPLE_QUOTE_STRING,
106+
APOS_STRING_LITERAL,
107+
QUOTE_STRING_LITERAL,
108+
hljs.C_NUMBER_MODE,
109+
hljs.HASH_COMMENT_MODE,
110+
],
111+
};
112+
}
113+
114+
module.exports = hljsDefineTurtle;

apps/bank/src/components/BusinessDataPanel.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import {Store, Writer} from 'n3';
33
import BusinessDataPanel from "@/components/BusinessDataPanel.vue";
44

55
jest.mock('@/assets/check.svg', () => 'mocked-check-icon-path');
6-
6+
jest.mock('highlight.js/styles/stackoverflow-light.css', () => 'mocked-check-icon-path');
7+
jest.mock('highlight.js/lib/core', () => ({
8+
highlightBlock: jest.fn(),
9+
registerLanguage: jest.fn()
10+
}));
711
describe('BusinessDataPanel.vue', () => {
812
let store: Store;
913
let writer: Writer;

apps/bank/src/components/BusinessDataPanel.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<script setup lang="ts">
2-
import { Store, Writer } from 'n3';
3-
import { ref } from 'vue';
2+
import {Store, Writer} from 'n3';
3+
import {onMounted, ref} from 'vue';
4+
import hljs from "highlight.js/lib/core";
5+
import hljsDefineTurtle from '../assets/highlightjs-turtle/turtle.js';
6+
import 'highlight.js/styles/stackoverflow-light.css';
7+
8+
hljs.registerLanguage('turtle', hljsDefineTurtle);
9+
10+
onMounted(() => {
11+
hljs.highlightBlock(document.querySelector('.turtle'));
12+
});
413
514
const props = defineProps({
615
store: Store
@@ -20,8 +29,8 @@ if (props.store) {
2029
</script>
2130

2231
<template>
23-
<div class="card bg-gray-50 border-round" style="background: rgba(232, 236, 239, 0.7); padding:0.5rem">
24-
<p class="m-0">{{ displayText }} </p>
32+
<div class="p-1">
33+
<pre><code ref="codeBlock" class="turtle border-round bg-gray-50">{{ displayText }}</code></pre>
2534
</div>
2635
<div class="success-message border-round">
2736
<p>Looks good: Automatic processing returned positive!

apps/bank/src/components/DemandProcessor.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PrimeVue from "primevue/config";
44
import ToastService from "primevue/toastservice";
55
import ConfirmationService from "primevue/confirmationservice";
66

7+
jest.mock('highlight.js/styles/stackoverflow-light.css', () => 'mocked-check-icon-path');
78
describe('DemandProcessor.vue', () => {
89
it('should render DemandProcessor', async() => {
910
const wrapper = mount(DemandProcessor, {

apps/bank/src/components/DemandProcessor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
</div>
7272

7373

74-
<Dialog v-model:visible="isDialogVisible" modal header="Requested business assessment data" :style="{ width: '55rem' }">
74+
<Dialog v-model:visible="isDialogVisible" modal header="Requested business assessment data" :style="{ width: '80%' }">
7575
<div v-if="!businessDataFetched">
7676
<Skeleton width="100%" height="300px" ></Skeleton>
7777
<Skeleton width="100%" height="50px" class="mb-5 mt-2"></Skeleton>

apps/bank/src/router/accessRequestHandledCallback.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import onResult from "@/router/accessRequestHandledCallback";
2+
jest.mock('highlight.js/styles/stackoverflow-light.css', () => 'mocked-check-icon-path');
23

34
describe('accessRequestHandledCallback', () => {
45
it('should memorize callback uri', async () => {

package-lock.json

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,22 @@
1616
"build": "lerna run build",
1717
"test": "lerna run test",
1818
"lint": "lerna run lint",
19-
2019
"version": "lerna version",
2120
"prepublish": "run-s libs:build",
2221
"publish": "lerna publish from-package",
23-
2422
"apps:build": "lerna run build --scope \"@apps/*\"",
2523
"apps:lint": "lerna run lint --scope \"@apps/*\"",
2624
"apps:test": "lerna run test --scope \"@apps/*\"",
27-
2825
"libs:build": "lerna run build --scope \"@datev-research/*\"",
2926
"libs:lint": "lerna run lint --scope \"@datev-research/*\"",
3027
"libs:test": "lerna run test --scope \"@datev-research/*\"",
31-
3228
"prepare": "husky"
3329
},
3430
"dependencies": {
3531
"@vueuse/components": "^11.1.0",
3632
"@vueuse/core": "^11.1.0",
3733
"axios": "^1.7.2",
34+
"highlight.js": "^11.9.0",
3835
"jose": "^5.4.0",
3936
"n3": "^1.16.2",
4037
"primeflex": "^3.3.1",
@@ -48,8 +45,8 @@
4845
"devDependencies": {
4946
"@fullhuman/postcss-purgecss": "^4.0.0",
5047
"@fullhuman/vue-cli-plugin-purgecss": "~6.0.0",
51-
"@types/n3": "^1.10.4",
5248
"@types/jest": "^29.0.0",
49+
"@types/n3": "^1.10.4",
5350
"@typescript-eslint/eslint-plugin": "^5.4.0",
5451
"@typescript-eslint/parser": "^5.4.0",
5552
"@vue/cli-plugin-babel": "~5.0.0",
@@ -62,11 +59,11 @@
6259
"eslint": "^7.32.0",
6360
"eslint-plugin-vue": "^8.0.3",
6461
"husky": "^9.1.6",
65-
"lerna": "^8.1.9",
6662
"jest": "^29.0.0",
67-
"ts-jest": "^29.0.0",
63+
"lerna": "^8.1.9",
6864
"sass": "^1.72.0",
6965
"sass-loader": "^16.0.2",
66+
"ts-jest": "^29.0.0",
7067
"typescript": "^5.4.5"
7168
},
7269
"workspaces": [

0 commit comments

Comments
 (0)