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

🔀 Consolidate id deduplication/simplification for JATS #468

Merged
merged 5 commits into from
Jul 10, 2023
Merged
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
6 changes: 6 additions & 0 deletions .changeset/dry-poems-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'myst-to-tex': patch
'myst-cli': patch
---

Clean up tex errors associated with legends and empty outputs
6 changes: 6 additions & 0 deletions .changeset/fast-plants-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'myst-to-jats': patch
'myst-cli': patch
---

Consolidate id deduplication/simplification for JATS to isolated myst-to-jats transforms
70 changes: 35 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/jats-to-myst/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"doi-utils": "^2.0.0",
"jats-tags": "^1.0.0",
"jats-xml": "^1.0.1",
"myst-common": "^1.0.2",
"myst-frontmatter": "^1.0.2",
"myst-common": "^1.0.3",
"myst-frontmatter": "^1.0.3",
"myst-spec": "^0.0.4",
"myst-spec-ext": "^1.0.2",
"myst-transforms": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/jtex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"commander": "^10.0.1",
"js-yaml": "^4.1.0",
"myst-cli-utils": "^2.0.1",
"myst-frontmatter": "^1.0.2",
"myst-frontmatter": "^1.0.3",
"myst-templates": "^1.0.2",
"node-fetch": "^3.3.1",
"nunjucks": "^3.2.4",
Expand Down
12 changes: 5 additions & 7 deletions packages/myst-cli/src/process/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ function createOutputDirective(): { myst: string; id: string } {
return { myst: `\`\`\`{output}\n:id: ${id}\n\`\`\``, id };
}

function blockDivider(cell: ICell, index: number) {
const id =
cell.metadata.id ?? `nb-cell-${index}-${computeHash(JSON.stringify(cell)).substring(0, 10)}`;
function blockDivider(cell: ICell) {
const type = cell.cell_type === CELL_TYPES.code ? NotebookCell.code : NotebookCell.content;
return `+++ ${JSON.stringify({ id, type, ...cell.metadata })}\n\n`;
return `+++ ${JSON.stringify({ type, ...cell.metadata })}\n\n`;
}

export async function processNotebook(
Expand Down Expand Up @@ -55,10 +53,10 @@ export async function processNotebook(
const cellContent = asString(cell.source);
// If the first cell is a frontmatter block, do not put a block break above it
const omitBlockDivider = index === 0 && cellContent.startsWith('---\n');
return acc.concat(`${omitBlockDivider ? '' : blockDivider(cell, index)}${cellContent}`);
return acc.concat(`${omitBlockDivider ? '' : blockDivider(cell)}${cellContent}`);
}
if (cell.cell_type === CELL_TYPES.raw) {
return acc.concat(`${blockDivider(cell, index)}\`\`\`\n${asString(cell.source)}\n\`\`\``);
return acc.concat(`${blockDivider(cell)}\`\`\`\n${asString(cell.source)}\n\`\`\``);
}
if (cell.cell_type === CELL_TYPES.code) {
const code = `\`\`\`{code-cell} ${language}\n${asString(cell.source)}\n\`\`\``;
Expand All @@ -73,7 +71,7 @@ export async function processNotebook(
} else {
outputMap[id] = [];
}
return acc.concat(`${blockDivider(cell, index)}${code}\n\n${myst}`);
return acc.concat(`${blockDivider(cell)}${code}\n\n${myst}`);
}
return acc;
}, Promise.resolve([] as string[]));
Expand Down
6 changes: 6 additions & 0 deletions packages/myst-cli/src/transforms/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { computeHash } from 'myst-cli-utils';
import { SourceFileKind } from 'myst-common';
import type { GenericNode } from 'myst-common';
import stripAnsi from 'strip-ansi';
import { remove } from 'unist-util-remove';
import { selectAll } from 'unist-util-select';
import type { IOutput } from '@jupyterlab/nbformat';
import { extFromMimeType, minifyCellOutput, walkOutputs } from 'nbtx';
Expand Down Expand Up @@ -66,6 +67,10 @@ export async function transformOutputs(
export function reduceOutputs(mdast: Root, writeFolder: string) {
const outputs = selectAll('output', mdast) as GenericNode[];
outputs.forEach((node) => {
if (!node.data?.length) {
node.type = '__delete__';
return;
}
let selectedOutput: { content_type: string; path: string; hash: string } | undefined;
walkOutputs(node.data, (obj: any) => {
if (selectedOutput || !obj.path || !obj.hash) return;
Expand Down Expand Up @@ -94,4 +99,5 @@ export function reduceOutputs(mdast: Root, writeFolder: string) {
delete node.id;
}
});
remove(mdast, '__delete__');
}
2 changes: 1 addition & 1 deletion packages/myst-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"url": "https://github.com/executablebooks/mystmd/issues"
},
"dependencies": {
"myst-frontmatter": "^1.0.2",
"myst-frontmatter": "^1.0.3",
"simple-validators": "^1.0.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-directives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"js-yaml": "^4.1.0",
"myst-common": "^1.0.2",
"myst-common": "^1.0.3",
"myst-spec-ext": "^1.0.2",
"vfile": "^5.3.7"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-ext-card/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"url": "https://github.com/executablebooks/mystmd/issues"
},
"dependencies": {
"myst-common": "^1.0.2"
"myst-common": "^1.0.3"
},
"devDependencies": {
"myst-parser": "^1.0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-ext-exercise/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"url": "https://github.com/executablebooks/mystmd/issues"
},
"dependencies": {
"myst-common": "^1.0.2"
"myst-common": "^1.0.3"
},
"devDependencies": {
"myst-parser": "^1.0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-ext-grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"url": "https://github.com/executablebooks/mystmd/issues"
},
"dependencies": {
"myst-common": "^1.0.2"
"myst-common": "^1.0.3"
},
"devDependencies": {
"myst-parser": "^1.0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-ext-proof/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"url": "https://github.com/executablebooks/mystmd/issues"
},
"dependencies": {
"myst-common": "^1.0.2"
"myst-common": "^1.0.3"
},
"devDependencies": {
"myst-parser": "^1.0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-ext-reactive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"url": "https://github.com/executablebooks/mystmd/issues"
},
"dependencies": {
"myst-common": "^1.0.2"
"myst-common": "^1.0.3"
},
"devDependencies": {
"myst-parser": "^1.0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-ext-tabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"url": "https://github.com/executablebooks/mystmd/issues"
},
"dependencies": {
"myst-common": "^1.0.2"
"myst-common": "^1.0.3"
},
"devDependencies": {
"myst-parser": "^1.0.3"
Expand Down
Loading