diff --git a/.changeset/thin-hoops-itch.md b/.changeset/thin-hoops-itch.md new file mode 100644 index 000000000..65fc5f9c9 --- /dev/null +++ b/.changeset/thin-hoops-itch.md @@ -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 diff --git a/.changeset/twelve-experts-pick.md b/.changeset/twelve-experts-pick.md new file mode 100644 index 000000000..8f0355903 --- /dev/null +++ b/.changeset/twelve-experts-pick.md @@ -0,0 +1,5 @@ +--- +'@lblod/ember-rdfa-editor': patch +--- + +Add extra check to `postProcessTagAsRdfaNode` function to correctly parse older style literal nodes diff --git a/packages/ember-rdfa-editor/src/plugins/heading/nodes/heading.ts b/packages/ember-rdfa-editor/src/plugins/heading/nodes/heading.ts index 93cb34f20..28302df93 100644 --- a/packages/ember-rdfa-editor/src/plugins/heading/nodes/heading.ts +++ b/packages/ember-rdfa-editor/src/plugins/heading/nodes/heading.ts @@ -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'; @@ -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 = { @@ -36,25 +27,54 @@ 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, @@ -62,9 +82,8 @@ export const headingWithConfig: (config?: Config) => SayNodeSpec = ({ ), alignment: getAlignment(node), }; - return { ...baseAttrs, ...getRdfaAttrs(node, { rdfaAware }) }; + return attrs; }, - contentElement: getRdfaContentElement, }, ], toDOM(node: PNode) { @@ -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, + ]; }, }; }; diff --git a/test-app/app/templates/editable-node.gts b/test-app/app/templates/editable-node.gts index 0ccd1af5a..b5d9243c9 100644 --- a/test-app/app/templates/editable-node.gts +++ b/test-app/app/templates/editable-node.gts @@ -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, diff --git a/test-app/tests/unit/rdfa/rdfa-parsing-test.ts b/test-app/tests/unit/rdfa/rdfa-parsing-test.ts index 6295cef3b..eb074a972 100644 --- a/test-app/tests/unit/rdfa/rdfa-parsing-test.ts +++ b/test-app/tests/unit/rdfa/rdfa-parsing-test.ts @@ -92,7 +92,7 @@ const schema = new Schema({ tableGroup: 'block', cellContent: 'block+', }), - heading: headingWithConfig({ rdfaAware: true }), + heading: headingWithConfig(), blockquote, horizontal_rule, @@ -798,7 +798,7 @@ module('rdfa | parsing', function () { }, ] satisfies OutgoingTriple[], }, - heading( + block_rdfa( { rdfaNodeType: 'literal', __rdfaId: 'literal-1', @@ -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', + ), ), ), );