Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for about attributes when parsing rdfa relationships #1052

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

piemonkey
Copy link
Contributor

@piemonkey piemonkey commented Nov 30, 2023

Overview

Adds about to the parsing of rdfa to establish properties and backlinks.

connected issues and PRs:

lblod/ember-rdfa-editor-lblod-plugins#358

Setup

Easiest used with the PR from plugins with article structure plugin changes.

How to test/reproduce

In the latest version of that PR, look at the properties and backlinks for say:heading nodes. After refresh, these were not correctly maintained, this PR corrects that.

Challenges/uncertainties

Checks PR readiness

  • UI: works on smaller screen sizes
  • UI: feedback for any loading/error states
  • Check cancel/go-back flows
  • Check database state correct when deleting/updating (especially regarding relationships)
  • changelog
  • npm lint
  • no new deprecations

}
if (type === 'resource') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is already merged, but I didn't notice before

so if I understand correctly this is making sure resource nodes have a resource attribute, even if there is none in the dom, right?
It's a bit janky cause it relies on the ordering of the rdfaDomAttrs constant, and Object.keys looping over the keys in order (which is probably in the spec, but still it's a bit fragile)

I'd do these checks after the loop to make it a bit more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're misreading the ordering. The idea here is that if the rdfaNodeType is resource it will make sure that the resource and properties fields are defined on the attrs object. If they have already been set it will keep them the same, if not, it will set them to '' or []. This is just to avoid getting undefined when attempting to access them, and to conform to the stricter types that I added. I'll add a note about what it's doing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah it would indeed be fine cause we don't overwrite when there's no value, so even if we hit resource later in the loop we would either overwrite it with the right value, or not do anything
I'd still put it outside of the loop personally, but its preference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. The typing is easier this way though, so I'll leave it here. As soon as I set rdfaNodeType to be resource, it insists that the others are present.

};
case 'about': {
const about = value as unknown as string;
const property = node.attributes.getNamedItem('property')?.value;
Copy link
Member

@abeforgit abeforgit Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned this is necessary. The idea is that we run the html through a spec-compliant rdfa parser, which "should" be able to generate the correct backlinks and properties, so by the time it gets to this logic we shouldn't have to worry about it anymore, can you elaborate on what's going wrong here?
(there's a good chance our parsing logic is wrong, but then I'd rather fix it there)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so the issue I'm seeing is that if I insert a structure, say a chapter, then the chapter resource has heading and title properties, each of which have the correct backlinks. If I then refresh, the heading is no longer correctly linked to the chapter (either the property on the chapter or the backlink on the heading.

It may well be that there is an issue with the parser that means it's missing these relations (they're in the DOM with an about and property attribute on the heading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've confirmed that there is a parser issue, I'll wait for that change, confirm that it's fixed, and remove this from the PR when done. This PR will then just be an improved comment...

@piemonkey
Copy link
Contributor Author

I'm going to merge this now since it's just a comment.

@piemonkey piemonkey merged commit f51503e into feat/rdfa-links-ui Dec 7, 2023
@piemonkey piemonkey deleted the rdfa/rdfa-about branch December 7, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants