Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render property fields with type rdf:HTML #170

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"pinia": "^2.1.7",
"vite-plugin-rewrite-all": "^1.0.1",
"vue": "^3.3.0",
"vue-dompurify-html": "^5.1.0",
"vue-router": "^4.2.5"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions src/components/proptable/ObjectCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const geometryPreds = [
"http://www.opengis.net/ont/geosparql#wktLiteral"
];

const renderHTMLPreds = [
"http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML"
]

const MAX_GEOM_LENGTH = 100; // max character length for geometry strings
</script>

Expand All @@ -30,6 +34,7 @@ const MAX_GEOM_LENGTH = 100; // max character length for geometry strings
<pre>{{ props.value.length > MAX_GEOM_LENGTH ? `${props.value.slice(0, MAX_GEOM_LENGTH)}...` : props.value }}</pre>
<button class="btn outline sm" title="Copy geometry" @click="copyToClipboard(props.value)"><i class="fa-regular fa-clipboard"></i></button>
</div>
<div v-else-if="props.datatype && renderHTMLPreds.includes(props.datatype.value)" class="html-cell" v-dompurify-html="props.value"></div>
<div v-else-if="props.datatype && props.datatype.qname === 'xsd:double'">
{{ Number(props.value) }}
</div>
Expand Down
13 changes: 12 additions & 1 deletion src/components/proptable/PropTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ function buildRows(properties: AnnotatedTriple[]): PropTableRow[] {
return Object.values(propRows).sort((a, b) => a.order - b.order);
}

function isHTML(content: string): boolean {
let ret = false;
for (let tag of ["<h2","<h3", "<p"]) {
if (content.indexOf(tag) !== -1) {
ret = true;
break;
}
}
return ret;
}
onMounted(() => {
const properties = props.properties.filter(p => !props.hiddenPredicates.includes(p.predicate.value));
rows.value = buildRows(properties);
Expand Down Expand Up @@ -67,7 +77,8 @@ onMounted(() => {
</small>
</h1>
<slot name="map"></slot>
<p v-if="!!props.item.description"><em>{{ props.item.description }}</em></p>
<div v-if="(!!props.item.description && isHTML(props.item.description))" v-dompurify-html="props.item.description"></div>
<p v-else-if="!!props.item.description"><em>{{ props.item.description }}</em></p>
<table>
<slot name="top"></slot>
<PropRow v-for="row in rows" v-bind="row" />
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import router from "@/router";
import config from "@/config";
import { sidenavConfigKey, enabledPrezsConfigKey, apiBaseUrlConfigKey, mapConfigKey, perPageConfigKey, conceptPerPageConfigKey, enableScoresKey } from "@/types";
import { Tooltip } from "floating-vue";
import VueDOMPurifyHTML from 'vue-dompurify-html';
import VueGoogleMaps from "@fawmi/vue-google-maps";

import "floating-vue/dist/style.css";
Expand All @@ -29,6 +30,7 @@ app.use(VueGoogleMaps, {
libraries: "drawing"
},
})
app.use(VueDOMPurifyHTML);
app.component("Tooltip", Tooltip);
// disable warnings for TreeSelect
app.component("transition", Transition);
Expand Down
Loading