Skip to content

Commit 3de00c8

Browse files
authored
Merge pull request #1323 from lblod/GN-5607-fix-old-template-literal-node-parsing
GN-5607: correctly parse older-style literal nodes
2 parents 329a9d1 + b14fd1b commit 3de00c8

File tree

4 files changed

+119
-1
lines changed

4 files changed

+119
-1
lines changed

.changeset/twelve-experts-pick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lblod/ember-rdfa-editor': patch
3+
---
4+
5+
Add extra check to `postProcessTagAsRdfaNode` function to correctly parse older style literal nodes

packages/ember-rdfa-editor/src/utils/_private/rdfa-parser/post-process-as-rdfa-nodes.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface PostProcessArgs<N> {
55
activeTag: IActiveTag<N>;
66
attributes: Record<string, string>;
77
isRootTag: boolean;
8+
isExternalTriple: boolean;
89
typedResource: true | ModelBlankNode<N> | ModelNamedNode<N> | null;
910
markAsLiteralNode: (
1011
node: N,
@@ -76,11 +77,25 @@ export function postProcessTagAsRdfaNode<N>(args: PostProcessArgs<N>): void {
7677
activeTag,
7778
attributes,
7879
isRootTag,
80+
isExternalTriple,
7981
typedResource,
8082
markAsLiteralNode,
8183
markAsResourceNode,
8284
} = args;
8385
const node = activeTag.node;
86+
if (node && isExternalTriple) {
87+
markAsResourceNode(
88+
node,
89+
unwrap(activeTag.subject),
90+
activeTag,
91+
activeTag.predicates?.find(
92+
(pred) => pred.value === attributes['property'],
93+
),
94+
activeTag.datatype,
95+
activeTag.language,
96+
);
97+
return;
98+
}
8499
if (!activeTag.skipElement && node) {
85100
// no rel or rev
86101
if (
@@ -120,7 +135,9 @@ export function postProcessTagAsRdfaNode<N>(args: PostProcessArgs<N>): void {
120135
} else {
121136
if (
122137
truthyAttribute(attributes, 'about') &&
123-
!truthyAttribute(attributes, 'data-literal-node')
138+
!truthyAttribute(attributes, 'data-literal-node') &&
139+
// Is this correct, an alternative solution would be to check on the presence of a `resource` attr here?
140+
!truthyAttribute(attributes, 'datatype')
124141
) {
125142
// same exception as above, we always interpret (property +about -content) cases as literal nodes
126143
markAsResourceNode(

packages/ember-rdfa-editor/src/utils/_private/rdfa-parser/rdfa-parser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,10 +1204,14 @@ export class RdfaParser<N> {
12041204
}
12051205
}
12061206
const isRootTag: boolean = this.activeTagStack.length === 1;
1207+
const isExternalTriple = Boolean(
1208+
parentTag?.attributes['data-external-triple-container'],
1209+
);
12071210
postProcessTagAsRdfaNode({
12081211
activeTag,
12091212
attributes: activeTag.attributes,
12101213
isRootTag,
1214+
isExternalTriple,
12111215
typedResource: activeTag.typedResource ?? null,
12121216
markAsLiteralNode: this.markAsLiteralNode,
12131217
markAsResourceNode: this.markAsResourceNode,

test-app/tests/unit/rdfa/rdfa-parsing-test.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,4 +733,96 @@ module('rdfa | parsing', function () {
733733
const resultingDocument = controller.mainEditorState.doc;
734734
assert.propEqual(resultingDocument.toJSON(), initialDocument.toJSON());
735735
});
736+
test('Older documents with older style literal nodes should be correctly parsed', function (assert) {
737+
QUnit.dump.maxDepth = 10;
738+
const html = `
739+
<div
740+
lang="nl-BE"
741+
data-say-document="true"
742+
data-literal-node="true"
743+
>
744+
<div
745+
style="display: none"
746+
class="say-hidden"
747+
data-rdfa-container="true"
748+
></div>
749+
<div data-content-container="true">
750+
<div
751+
class="say-editable say-block-rdfa"
752+
about="http://data.lblod.info/id/besluiten/1"
753+
data-say-id="30e2d215-a8b6-4bab-9d8b-aaab634589ea"
754+
>
755+
<div
756+
style="display: none"
757+
class="say-hidden"
758+
data-rdfa-container="true"
759+
>
760+
<span
761+
about="http://data.lblod.info/id/besluiten/1"
762+
property="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
763+
resource="http://data.vlaanderen.be/ns/besluit#Besluit"
764+
></span>
765+
</div>
766+
<div data-content-container="true">
767+
<h4
768+
property="http://data.europa.eu/eli/ontology#title"
769+
about="http://data.lblod.info/id/besluiten/1"
770+
datatype="http://www.w3.org/2001/XMLSchema#string"
771+
data-say-id="literal-1"
772+
lang=""
773+
>Decision title</h4>
774+
</div>
775+
</div>
776+
</div>
777+
</div>
778+
`;
779+
const { doc, block_rdfa, heading } = testBuilders;
780+
const df = new SayDataFactory();
781+
const expectedDoc = doc(
782+
{},
783+
block_rdfa(
784+
{
785+
rdfaNodeType: 'resource',
786+
subject: 'http://data.lblod.info/id/besluiten/1',
787+
__rdfaId: '30e2d215-a8b6-4bab-9d8b-aaab634589ea',
788+
properties: [
789+
{
790+
predicate: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
791+
object: df.namedNode(
792+
'http://data.vlaanderen.be/ns/besluit#Besluit',
793+
),
794+
},
795+
{
796+
predicate: 'http://data.europa.eu/eli/ontology#title',
797+
object: df.literalNode('literal-1'),
798+
},
799+
] satisfies OutgoingTriple[],
800+
},
801+
heading(
802+
{
803+
rdfaNodeType: 'literal',
804+
__rdfaId: 'literal-1',
805+
backlinks: [
806+
{
807+
predicate: 'http://data.europa.eu/eli/ontology#title',
808+
subject: sayDataFactory.resourceNode(
809+
'http://data.lblod.info/id/besluiten/1',
810+
),
811+
},
812+
],
813+
datatype: sayDataFactory.namedNode(
814+
'http://www.w3.org/2001/XMLSchema#string',
815+
),
816+
language: '',
817+
level: 4,
818+
},
819+
'Decision title',
820+
),
821+
),
822+
);
823+
const { controller } = testEditor(schema, plugins);
824+
controller.initialize(html);
825+
const actualDoc = controller.mainEditorState.doc;
826+
assert.propEqual(actualDoc.toJSON(), expectedDoc.toJSON());
827+
});
736828
});

0 commit comments

Comments
 (0)