Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/twelve-experts-pick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lblod/ember-rdfa-editor': patch
---

Add extra check to `postProcessTagAsRdfaNode` function to correctly parse older style literal nodes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface PostProcessArgs<N> {
activeTag: IActiveTag<N>;
attributes: Record<string, string>;
isRootTag: boolean;
isExternalTriple: boolean;
typedResource: true | ModelBlankNode<N> | ModelNamedNode<N> | null;
markAsLiteralNode: (
node: N,
Expand Down Expand Up @@ -76,11 +77,25 @@ export function postProcessTagAsRdfaNode<N>(args: PostProcessArgs<N>): void {
activeTag,
attributes,
isRootTag,
isExternalTriple,
typedResource,
markAsLiteralNode,
markAsResourceNode,
} = args;
const node = activeTag.node;
if (node && isExternalTriple) {
markAsResourceNode(
node,
unwrap(activeTag.subject),
activeTag,
activeTag.predicates?.find(
(pred) => pred.value === attributes['property'],
),
activeTag.datatype,
activeTag.language,
);
return;
}
if (!activeTag.skipElement && node) {
// no rel or rev
if (
Expand Down Expand Up @@ -120,7 +135,9 @@ export function postProcessTagAsRdfaNode<N>(args: PostProcessArgs<N>): void {
} else {
if (
truthyAttribute(attributes, 'about') &&
!truthyAttribute(attributes, 'data-literal-node')
!truthyAttribute(attributes, 'data-literal-node') &&
// Is this correct, an alternative solution would be to check on the presence of a `resource` attr here?
!truthyAttribute(attributes, 'datatype')
) {
// same exception as above, we always interpret (property +about -content) cases as literal nodes
markAsResourceNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1204,10 +1204,14 @@ export class RdfaParser<N> {
}
}
const isRootTag: boolean = this.activeTagStack.length === 1;
const isExternalTriple = Boolean(
parentTag?.attributes['data-external-triple-container'],
);
postProcessTagAsRdfaNode({
activeTag,
attributes: activeTag.attributes,
isRootTag,
isExternalTriple,
typedResource: activeTag.typedResource ?? null,
markAsLiteralNode: this.markAsLiteralNode,
markAsResourceNode: this.markAsResourceNode,
Expand Down
92 changes: 92 additions & 0 deletions test-app/tests/unit/rdfa/rdfa-parsing-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,96 @@ module('rdfa | parsing', function () {
const resultingDocument = controller.mainEditorState.doc;
assert.propEqual(resultingDocument.toJSON(), initialDocument.toJSON());
});
test('Older documents with older style literal nodes should be correctly parsed', function (assert) {
QUnit.dump.maxDepth = 10;
const html = `
<div
lang="nl-BE"
data-say-document="true"
data-literal-node="true"
>
<div
style="display: none"
class="say-hidden"
data-rdfa-container="true"
></div>
<div data-content-container="true">
<div
class="say-editable say-block-rdfa"
about="http://data.lblod.info/id/besluiten/1"
data-say-id="30e2d215-a8b6-4bab-9d8b-aaab634589ea"
>
<div
style="display: none"
class="say-hidden"
data-rdfa-container="true"
>
<span
about="http://data.lblod.info/id/besluiten/1"
property="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
resource="http://data.vlaanderen.be/ns/besluit#Besluit"
></span>
</div>
<div data-content-container="true">
<h4
property="http://data.europa.eu/eli/ontology#title"
about="http://data.lblod.info/id/besluiten/1"
datatype="http://www.w3.org/2001/XMLSchema#string"
data-say-id="literal-1"
lang=""
>Decision title</h4>
</div>
</div>
</div>
</div>
`;
const { doc, block_rdfa, heading } = testBuilders;
const df = new SayDataFactory();
const expectedDoc = doc(
{},
block_rdfa(
{
rdfaNodeType: 'resource',
subject: 'http://data.lblod.info/id/besluiten/1',
__rdfaId: '30e2d215-a8b6-4bab-9d8b-aaab634589ea',
properties: [
{
predicate: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
object: df.namedNode(
'http://data.vlaanderen.be/ns/besluit#Besluit',
),
},
{
predicate: 'http://data.europa.eu/eli/ontology#title',
object: df.literalNode('literal-1'),
},
] satisfies OutgoingTriple[],
},
heading(
{
rdfaNodeType: 'literal',
__rdfaId: 'literal-1',
backlinks: [
{
predicate: 'http://data.europa.eu/eli/ontology#title',
subject: sayDataFactory.resourceNode(
'http://data.lblod.info/id/besluiten/1',
),
},
],
datatype: sayDataFactory.namedNode(
'http://www.w3.org/2001/XMLSchema#string',
),
language: '',
level: 4,
},
'Decision title',
),
),
);
const { controller } = testEditor(schema, plugins);
controller.initialize(html);
const actualDoc = controller.mainEditorState.doc;
assert.propEqual(actualDoc.toJSON(), expectedDoc.toJSON());
});
});