-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π©βπ JATS citation / affiliation fixes (#783)
* π©βπ Process parts along with content during jats render * π©βπ Only render used, ordered references in jats * π€― Return mutable copies from redux selectors * π§ Prevent empty ref-list elements in jats
- Loading branch information
Showing
11 changed files
with
171 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'myst-to-jats': patch | ||
--- | ||
|
||
Process parts along with content during jats render |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'myst-to-jats': patch | ||
--- | ||
|
||
Only render used, ordered references in jats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'myst-cli': patch | ||
--- | ||
|
||
Return mutable copies from redux selectors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,52 @@ | ||
import type { Plugin } from 'unified'; | ||
import type { Block } from 'myst-spec-ext'; | ||
import type { GenericParent } from 'myst-common'; | ||
import { selectBlockParts, type GenericParent } from 'myst-common'; | ||
import { remove } from 'unist-util-remove'; | ||
import { selectAll } from 'unist-util-select'; | ||
import { ABSTRACT_PARTS, ACKNOWLEDGMENT_PARTS, type Options } from '../types.js'; | ||
|
||
function blocksToKeep(tree: GenericParent, opts: Options) { | ||
const keepParts: string[] = [...ACKNOWLEDGMENT_PARTS]; | ||
if (opts.extractAbstract) { | ||
keepParts.push(...(opts.abstractParts?.map(({ part }) => part).flat() ?? ABSTRACT_PARTS)); | ||
} | ||
if (opts.backSections) { | ||
keepParts.push(...opts.backSections.map(({ part }) => part).flat()); | ||
} | ||
return selectBlockParts(tree, keepParts); | ||
} | ||
|
||
/** | ||
* This transform does the following: | ||
* - Removes hidden or removed blocks from the tree | ||
* - Removes hidden or removed blocks from the tree except those that are consumed as front/backmatter parts | ||
* - Removes hidden or removed outputs from the tree | ||
*/ | ||
export function blockTransform(tree: GenericParent) { | ||
export function blockTransform(tree: GenericParent, opts: Options) { | ||
// Collect blocks that will be used as parts to make sure they are not deleted | ||
const doNotDelete = blocksToKeep(tree, opts); | ||
// 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; | ||
}); | ||
const removed = remove(tree, '__delete__'); | ||
if (removed === null) { | ||
// remove is unhappy if all children are removed - this forces it through | ||
tree.children = []; | ||
} | ||
} | ||
|
||
export const blockPlugin: Plugin<[], GenericParent, GenericParent> = () => (tree) => { | ||
blockTransform(tree); | ||
export const blockPlugin: Plugin<[Options], GenericParent, GenericParent> = (opts) => (tree) => { | ||
blockTransform(tree, opts); | ||
}; | ||
|
||
export function restoreBlockPartTypeTransform(tree: GenericParent) { | ||
selectAll('block-part', tree).forEach((node) => { | ||
node.type = 'block'; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.