From c62dd480c3d0bce5f7c96e899db5dfdd99b31421 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Thu, 6 Feb 2025 11:21:56 +0000 Subject: [PATCH 1/4] test: add basic plugin test --- packages/mystmd/tests/basic-plugin/index.md | 7 + packages/mystmd/tests/basic-plugin/myst.yml | 24 ++++ packages/mystmd/tests/basic-plugin/plugin.mjs | 19 +++ packages/mystmd/tests/exports.yml | 7 + .../tests/outputs/basic-plugin-content.json | 128 ++++++++++++++++++ 5 files changed, 185 insertions(+) create mode 100644 packages/mystmd/tests/basic-plugin/index.md create mode 100644 packages/mystmd/tests/basic-plugin/myst.yml create mode 100644 packages/mystmd/tests/basic-plugin/plugin.mjs create mode 100644 packages/mystmd/tests/outputs/basic-plugin-content.json diff --git a/packages/mystmd/tests/basic-plugin/index.md b/packages/mystmd/tests/basic-plugin/index.md new file mode 100644 index 000000000..27c8e573f --- /dev/null +++ b/packages/mystmd/tests/basic-plugin/index.md @@ -0,0 +1,7 @@ +--- +title: Basic Test +--- + +# Lorem Ipsum + +Set {red}`this text` to a class of red. diff --git a/packages/mystmd/tests/basic-plugin/myst.yml b/packages/mystmd/tests/basic-plugin/myst.yml new file mode 100644 index 000000000..b49768b94 --- /dev/null +++ b/packages/mystmd/tests/basic-plugin/myst.yml @@ -0,0 +1,24 @@ +# See docs at: https://mystmd.org/guide/frontmatter +version: 1 +project: + id: 22c218e1-66c6-428f-9df9-a7f2c6a3bd76 + # title: + # description: + keywords: [] + authors: [] + github: https://github.com/jupyter-book/mystmd + # bibliography: [] + # + plugins: + - plugin.mjs +site: + template: ../templates/site/myst/book-theme + # title: + # options: + # favicon: favicon.ico + # logo: site_logo.png + nav: [] + actions: + - title: Learn More + url: https://mystmd.org/guide + domains: [] diff --git a/packages/mystmd/tests/basic-plugin/plugin.mjs b/packages/mystmd/tests/basic-plugin/plugin.mjs new file mode 100644 index 000000000..a1293e28a --- /dev/null +++ b/packages/mystmd/tests/basic-plugin/plugin.mjs @@ -0,0 +1,19 @@ +const redRole = { + name: 'red', + doc: 'An example role that sets a custom class.', + body: { + type: 'myst', + required: true, + }, + run(data) { + const children = data.body; + children.forEach((child) => { + child.class = child.class ? `${child.class} red` : 'red'; + }); + return children; + }, +}; + +const plugin = { name: 'Example role', roles: [redRole] }; + +export default plugin; diff --git a/packages/mystmd/tests/exports.yml b/packages/mystmd/tests/exports.yml index 6f569e964..09e7c05af 100644 --- a/packages/mystmd/tests/exports.yml +++ b/packages/mystmd/tests/exports.yml @@ -190,6 +190,13 @@ cases: content: outputs/basic-site-config.json - path: basic-site/_build/site/myst.xref.json content: outputs/basic-site-myst.xref.json + - title: Basic plugin build + cwd: basic-plugin + command: myst build + outputs: + - path: basic-plugin/_build/site/content/index.json + # Keys and file hashes are removed from this output file + content: outputs/basic-plugin-content.json - title: XRef site build cwd: site-xrefs command: myst build diff --git a/packages/mystmd/tests/outputs/basic-plugin-content.json b/packages/mystmd/tests/outputs/basic-plugin-content.json new file mode 100644 index 000000000..c4098ec3f --- /dev/null +++ b/packages/mystmd/tests/outputs/basic-plugin-content.json @@ -0,0 +1,128 @@ +{ + "kind": "Article", + "sha256": "900eec73ecdfd1641367698dab8e7727ce2a81122ba0cd641c61c4f0f3b30694", + "slug": "index", + "location": "/index.md", + "dependencies": [], + "frontmatter": { + "title": "Basic Test", + "github": "https://github.com/jupyter-book/mystmd", + "keywords": [], + "exports": [ + { + "format": "md", + "filename": "index.md", + "url": "/index-827a0078d531c946c69925141436e783.md" + } + ] + }, + "mdast": { + "type": "root", + "children": [ + { + "type": "block", + "children": [ + { + "type": "heading", + "depth": 2, + "position": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "children": [ + { + "type": "text", + "value": "Lorem Ipsum", + "position": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 1 + } + } + } + ], + "identifier": "lorem-ipsum", + "label": "Lorem Ipsum", + "html_id": "lorem-ipsum", + "implicit": true + }, + { + "type": "paragraph", + "position": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "children": [ + { + "type": "text", + "value": "Set ", + "position": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "text", + "value": "this text", + "position": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "class": "red" + }, + { + "type": "text", + "value": " to a class of red.", + "position": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 1 + } + } + } + ] + } + ] + } + ] + }, + "references": { + "cite": { + "order": [], + "data": {} + } + }, + "version": "1" +} From 82bb16eede254feb673349be573f2b78348ef861 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Thu, 6 Feb 2025 11:27:23 +0000 Subject: [PATCH 2/4] fix: use pathToFileURL for imports from the FS --- packages/myst-cli/src/plugins.ts | 4 +++- packages/mystmd/tests/outputs/basic-plugin-content.json | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/myst-cli/src/plugins.ts b/packages/myst-cli/src/plugins.ts index fbe9e4a7b..258e9e928 100644 --- a/packages/myst-cli/src/plugins.ts +++ b/packages/myst-cli/src/plugins.ts @@ -1,4 +1,5 @@ import fs from 'node:fs'; +import { pathToFileURL } from 'node:url'; import type { ISession } from './session/types.js'; import { selectors } from './store/index.js'; import { RuleId, plural, type MystPlugin, type ValidatedMystPlugin } from 'myst-common'; @@ -97,8 +98,9 @@ export async function loadPlugins(session: ISession): Promise Date: Thu, 6 Feb 2025 12:12:49 +0000 Subject: [PATCH 3/4] chore: add changeset --- .changeset/sixty-peas-do.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/sixty-peas-do.md diff --git a/.changeset/sixty-peas-do.md b/.changeset/sixty-peas-do.md new file mode 100644 index 000000000..deb90f89c --- /dev/null +++ b/.changeset/sixty-peas-do.md @@ -0,0 +1,6 @@ +--- +"myst-cli": patch +"mystmd": patch +--- + +Fix imports of plugins on Windows From e3606aae26a517739cc81ad927ce34698ea2bf5e Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Thu, 6 Feb 2025 12:18:50 +0000 Subject: [PATCH 4/4] fix: convert URL to string --- packages/myst-cli/src/plugins.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/myst-cli/src/plugins.ts b/packages/myst-cli/src/plugins.ts index 258e9e928..0c9a117e3 100644 --- a/packages/myst-cli/src/plugins.ts +++ b/packages/myst-cli/src/plugins.ts @@ -100,7 +100,7 @@ export async function loadPlugins(session: ISession): Promise