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

πŸ‘©β€πŸŽ“ JATS citation / affiliation fixes #783

Merged
merged 4 commits into from
Nov 27, 2023
Merged

Conversation

fwkoch
Copy link
Collaborator

@fwkoch fwkoch commented Nov 25, 2023

This PR addresses some of the tasks here - #347:

  • IDs of affiliations needs to be normalized
    • This was caused by immutable objects returned by selectors - not the first time we will be bitten by that stealthy bug. Now, selectors return mutable copies, so hopefully this will not get us again 🀞
  • parts need to be rendered after the ID normalization (citation labels are not being transformed)
    • now, parts are left in the tree for final myst-to-jats mdast transforms, then plucked off immediately before render
  • multiple unused references show up in the final jats
    • now, only the used references are added to the xml, not all available citations

// This could also be an output, etc.
(selectAll('[visibility=remove],[visibility=hide]', tree) as Block[]).forEach((node) => {
if (node.visibility === 'remove' || node.visibility === 'hide') {
(node as any).type = '__delete__';
}
});
// Blocks are converted to sections - avoid doing this for part blocks
doNotDelete.forEach((node) => {
node.type = 'block-part' as any;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a little sketchy - we want to include referenced parts in the transformations, but we do not want to include other hidden blocks.

So, first we find all the blocks that will be extracted as parts in blocksToKeep, then we make sure those are not marked for deletion here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

However, we must give them a type different from 'block' since in another transform, all blocks are converted to "sections"


export function restoreBlockPartTypeTransform(tree: GenericParent) {
selectAll('block-part', tree).forEach((node) => {
node.type = 'block';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Finally, once transformations are done, we return them to their original 'block' type, so the extractParts function will behave correctly. Pretty gross.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am leaving this grossness in, however, since I think the real fix is bulid JATS in unist (there's already some utility for this in jats-xml) - then, we will not need to do these extra jats-specific transforms on the input MyST AST; we instead can apply simpler, more sensible transforms to the output JATS AST.

@rowanc1 rowanc1 merged commit 5e6d1d3 into main Nov 27, 2023
4 checks passed
@rowanc1 rowanc1 deleted the feat/jats-ids branch November 27, 2023 18:20
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