Skip to content

Commit a803ce2

Browse files
committed
introduce seperate content property on activeTag
1 parent bf58c4f commit a803ce2

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface IActiveTag<N> {
2525
predicates?: ModelNamedNode<N>[] | null;
2626
object?: ModelNamedNode<N> | ModelBlankNode<N> | boolean | null;
2727
text?: string[] | null;
28+
content?: string | null; // contains `text` concatenated, or the `content` attribute
2829
vocab?: string;
2930
language?: string;
3031
datatype?: ModelNamedNode<N>;

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -979,11 +979,7 @@ export class RdfaParser<N> {
979979
attributes: Record<string, string>,
980980
predicateAttribute = 'property',
981981
) => {
982-
const textSegments: string[] = activeTag.text || [];
983-
const object = this.util.createLiteral(
984-
attributes['content'] ?? textSegments.join(''),
985-
activeTag,
986-
);
982+
const object = this.util.createLiteral(activeTag.content ?? '', activeTag);
987983
this.contentNodeMapping.set(node, {
988984
subject: sayDataFactory.resourceNode(
989985
this.util.getResourceOrBaseIri(unwrap(activeTag.subject), activeTag)
@@ -1049,6 +1045,14 @@ export class RdfaParser<N> {
10491045
const parentTag: IActiveTag<N> =
10501046
this.activeTagStack[this.activeTagStack.length - 2];
10511047

1048+
let textSegments: string[] = activeTag.text || [];
1049+
if (activeTag.collectChildTags && parentTag.collectChildTags) {
1050+
// If we are inside an XMLLiteral child that also has RDFa content, ignore the tag name that was collected.
1051+
textSegments = textSegments.slice(1);
1052+
}
1053+
activeTag.content =
1054+
activeTag.attributes['content'] ?? textSegments.join('');
1055+
10521056
if (
10531057
!(
10541058
activeTag.collectChildTags &&
@@ -1120,8 +1124,7 @@ export class RdfaParser<N> {
11201124

11211125
// Reset text, unless the parent is also collecting text
11221126
if (!parentTag.predicates) {
1123-
// Can we simply remove this statement?
1124-
// activeTag.text = null;
1127+
activeTag.text = null;
11251128
}
11261129
}
11271130

0 commit comments

Comments
 (0)