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

💬 Remove quotes around {eval} outputs #1806

Merged
merged 2 commits into from
Jan 23, 2025
Merged
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
5 changes: 5 additions & 0 deletions .changeset/spotty-melons-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-cli": patch
---

Remove quotes around plain text for eval outputs
26 changes: 26 additions & 0 deletions packages/myst-cli/src/transforms/inlineExpression.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, expect, it } from 'vitest';
import { transformRenderInlineExpressions } from './inlineExpressions';
import { VFile } from 'vfile';
import type { InlineExpression } from 'myst-spec-ext';

describe('fileFromRelativePath', () => {
it('inline text is not quoted', async () => {
const vfile = new VFile();
const expr = {
type: 'inlineExpression',
value: '"hello " + "there"',
result: {
status: 'ok',
data: {
// Note the wrapping quotes!
'text/plain': "'hello there'",
},
metadata: {},
},
} as InlineExpression;
const tree = { type: 'root', children: [expr] };
transformRenderInlineExpressions(tree, vfile);
// Children are added and quotes are removed
expect(expr.children).toEqual([{ type: 'text', value: 'hello there' }]);
});
});
6 changes: 5 additions & 1 deletion packages/myst-cli/src/transforms/inlineExpressions.ts
Original file line number Diff line number Diff line change
@@ -33,6 +33,10 @@ function processLatex(value: string) {
.trim();
}

function processPlainText(content: string) {
return content.replace(/^(["'])(.*)\1$/, '$2');
}

function renderExpression(node: InlineExpression, file: VFile): StaticPhrasingContent[] {
const result = node.result as IExpressionResult;
if (!result) return [];
@@ -53,7 +57,7 @@ function renderExpression(node: InlineExpression, file: VFile): StaticPhrasingCo
} else if (mimeType === 'text/html') {
content = [{ type: 'html', value: value as string }];
} else if (mimeType === 'text/plain') {
content = [{ type: 'text', value: value as string }];
content = [{ type: 'text', value: processPlainText(value as string) }];
}
});
if (content) return content;

Unchanged files with check annotations Beta

import type { VFile } from 'vfile';
import type { GenericNode } from 'myst-common';
import { fileError, fileWarn, toText, getMetadataTags } from 'myst-common';
import { captionHandler, containerHandler, getDefaultCaptionSupplement } from './container.js';

Check warning on line 6 in packages/myst-to-typst/src/index.ts

GitHub Actions / lint

'getDefaultCaptionSupplement' is defined but never used
import type {
Handler,
ITypstSerializer,
constructor(opts?: { logger?: Logger }) {
this.log = opts?.logger ?? chalkLogger(LogLevel.debug, process.cwd());
}
fetch(url: URL | RequestInfo, init?: RequestInit | undefined): Promise<Response> {

Check warning on line 10 in packages/myst-cli-utils/src/session.ts

GitHub Actions / lint

'url' is defined but never used

Check warning on line 10 in packages/myst-cli-utils/src/session.ts

GitHub Actions / lint

'init' is defined but never used
throw new Error('fetch not implemented on session');
}
}
import type { JSONSchema7Definition } from 'json-schema';
const LicenseSchema: JSONSchema7Definition = {

Check warning on line 3 in packages/myst-frontmatter/src/licenses/schema.ts

GitHub Actions / lint

'LicenseSchema' is assigned a value but never used
$id: '',
description:
'The license information, which can be either a string or an object with `code` and `content`.',
import { cleanOutput } from './utils/cleanOutput.js';
import { getFileContent } from './utils/getFileContent.js';
import { resolveFrontmatterParts } from '../utils/resolveFrontmatterParts.js';
import { parseMyst } from '../process/myst.js';

Check warning on line 18 in packages/myst-cli/src/build/cff.ts

GitHub Actions / lint

'parseMyst' is defined but never used
function exportOptionsToCFF(exportOptions: ExportWithOutput): CFF {
// Handle overlap of key "format" between CFF and export
mdast: GenericParent,
references: References,
frontmatter: PageFrontmatter,
templateYml: TemplateYml | null,

Check warning on line 69 in packages/myst-cli/src/build/typst.ts

GitHub Actions / lint

'templateYml' is defined but never used
printGlossaries: boolean,

Check warning on line 70 in packages/myst-cli/src/build/typst.ts

GitHub Actions / lint

'printGlossaries' is defined but never used
) {
const pipe = unified().use(mystToTypst, {
math: frontmatter?.math,
}
};
const { root, defaults, format: _, ...rest } = data;

Check warning on line 335 in packages/myst-cli/src/init/jupyter-book/toc.ts

GitHub Actions / lint

'_' is assigned a value but never used
let result = {
root,
defaults,
return { options, ...convertSubtree(rest) };
}
};
const { root, defaults, format: _, ...rest } = data;

Check warning on line 383 in packages/myst-cli/src/init/jupyter-book/toc.ts

GitHub Actions / lint

'_' is assigned a value but never used
let result = {
root,
defaults,
ICell,
IMimeBundle,
INotebookContent,
INotebookMetadata,

Check warning on line 10 in packages/myst-cli/src/process/notebook.ts

GitHub Actions / lint

'INotebookMetadata' is defined but never used
IOutput,
MultilineString,
} from '@jupyterlab/nbformat';