Skip to content
Draft
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/thin-hoops-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lblod/ember-rdfa-editor': patch
---

rdfa-parser: fix issue where two relationships with the same subject and predicate pointing to literal-nodes/literals was not correctly parsed
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
95 changes: 51 additions & 44 deletions packages/ember-rdfa-editor/src/plugins/heading/nodes/heading.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Node as PNode } from 'prosemirror-model';
import {
getRdfaAttrs,
getRdfaContentElement,
rdfaAttrSpec,
renderRdfaAware,
} from '#root/core/schema.ts';
import { Fragment, Node as PNode } from 'prosemirror-model';
import { getRdfaAttrs, getRdfaContentElement } from '#root/core/schema.ts';
import { optionMapOr } from '#root/utils/_private/option.ts';
import type SayNodeSpec from '#root/core/say-node-spec.ts';
import NumberEditor from '#root/components/_private/utils/number-editor.gts';
Expand All @@ -13,14 +8,10 @@ import { DEFAULT_ALIGNMENT, getAlignment } from '../../alignment/index.ts';
import { HEADING_ELEMENTS } from '#root/utils/_private/constants.ts';
import { getHeadingLevel } from '#root/utils/_private/html-utils.ts';
import getClassnamesFromNode from '#root/utils/get-classnames-from-node.ts';
import type { Schema } from 'prosemirror-model';
import { ProseParser } from '#root/prosemirror-aliases.ts';

type Config = {
rdfaAware?: boolean;
};

export const headingWithConfig: (config?: Config) => SayNodeSpec = ({
rdfaAware = false,
} = {}) => {
export const headingWithConfig: () => SayNodeSpec = () => {
return {
get attrs() {
const commonAttrs = {
Expand All @@ -36,35 +27,63 @@ export const headingWithConfig: (config?: Config) => SayNodeSpec = ({
},
alignment: { default: DEFAULT_ALIGNMENT },
};
return { ...commonAttrs, ...rdfaAttrSpec({ rdfaAware }) };
return commonAttrs;
},
content: 'inline*',
group: 'block',
defining: true,
editable: rdfaAware,
isolating: rdfaAware,
selectable: rdfaAware,
editable: false,
isolating: false,
selectable: false,
classNames: ['say-heading'],
parseDOM: [
{
tag: HEADING_ELEMENTS.join(','),
node: 'block_rdfa',
getAttrs(node: string | HTMLElement) {
if (!(node instanceof HTMLHeadingElement)) {
return false;
}
const rdfaAttrs = getRdfaAttrs(node, { rdfaAware: true });
if (!rdfaAttrs) {
return false;
}
return rdfaAttrs;
},
getContent: (node: HTMLHeadingElement, schema: Schema) => {
const headingAttrs = {
level: getHeadingLevel(node),
indentationLevel: optionMapOr(
0,
parseInt,
node.dataset['indentationLevel'],
),
alignment: getAlignment(node),
};
const parser = ProseParser.fromSchema(schema);
const slice = parser.parseSlice(getRdfaContentElement(node));
return Fragment.from(
schema.nodes['heading'].create(headingAttrs, slice.content),
);
},
},
{
tag: HEADING_ELEMENTS.join(','),
getAttrs(node: string | HTMLElement) {
if (!(node instanceof HTMLHeadingElement)) {
return false;
}
const level = getHeadingLevel(node);
const baseAttrs = {
level,
const attrs = {
level: getHeadingLevel(node),
indentationLevel: optionMapOr(
0,
parseInt,
node.dataset['indentationLevel'],
),
alignment: getAlignment(node),
};
return { ...baseAttrs, ...getRdfaAttrs(node, { rdfaAware }) };
return attrs;
},
contentElement: getRdfaContentElement,
},
],
toDOM(node: PNode) {
Expand All @@ -77,27 +96,15 @@ export const headingWithConfig: (config?: Config) => SayNodeSpec = ({
'data-indentation-level': indentationLevel as number,
style,
};
if (rdfaAware) {
return renderRdfaAware({
tag: `h${(level as number).toString()}`,
renderable: node,
attrs: {
...baseAttrs,
class: `say-editable ${getClassnamesFromNode(node)}`,
},
content: 0,
});
} else {
return [
`h${(level as number).toString()}`,
{
...baseAttrs,
...node.attrs,
class: getClassnamesFromNode(node),
},
0,
];
}
return [
`h${(level as number).toString()}`,
{
...baseAttrs,
...node.attrs,
class: getClassnamesFromNode(node),
},
0,
];
},
};
};
Expand Down
2 changes: 1 addition & 1 deletion test-app/app/templates/editable-node.gts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export default class extends Component {
cellContent: 'block+',
inlineBorderStyle: { width: '0.5px', color: '#CCD1D9' },
}),
heading: headingWithConfig({ rdfaAware: false }),
heading: headingWithConfig(),
blockquote,

horizontal_rule,
Expand Down
12 changes: 8 additions & 4 deletions test-app/tests/unit/rdfa/rdfa-parsing-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const schema = new Schema({
tableGroup: 'block',
cellContent: 'block+',
}),
heading: headingWithConfig({ rdfaAware: true }),
heading: headingWithConfig(),
blockquote,

horizontal_rule,
Expand Down Expand Up @@ -798,7 +798,7 @@ module('rdfa | parsing', function () {
},
] satisfies OutgoingTriple[],
},
heading(
block_rdfa(
{
rdfaNodeType: 'literal',
__rdfaId: 'literal-1',
Expand All @@ -814,9 +814,13 @@ module('rdfa | parsing', function () {
'http://www.w3.org/2001/XMLSchema#string',
),
language: '',
level: 4,
},
'Decision title',
heading(
{
level: 4,
},
'Decision title',
),
),
),
);
Expand Down