From 3950dcaa02e5cb0750e88ab1541166b0d471cfea Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Mon, 6 Jan 2025 14:42:00 -0700 Subject: [PATCH] =?UTF-8?q?=E2=8C=A8=EF=B8=8F=20Do=20not=20export=20code?= =?UTF-8?q?=20block=20options=20when=20undefined=20(#1721)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Franklin Koch --- .changeset/wicked-gifts-walk.md | 5 +++++ packages/myst-to-md/src/directives.ts | 4 +++- packages/myst-to-md/tests/directives.yml | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .changeset/wicked-gifts-walk.md diff --git a/.changeset/wicked-gifts-walk.md b/.changeset/wicked-gifts-walk.md new file mode 100644 index 000000000..7f317b6ec --- /dev/null +++ b/.changeset/wicked-gifts-walk.md @@ -0,0 +1,5 @@ +--- +"myst-to-md": patch +--- + +Do not have code block options exported when they are null diff --git a/packages/myst-to-md/src/directives.ts b/packages/myst-to-md/src/directives.ts index d855d548d..93558289b 100644 --- a/packages/myst-to-md/src/directives.ts +++ b/packages/myst-to-md/src/directives.ts @@ -98,7 +98,9 @@ const CODE_BLOCK_KEYS = [ * non-directive code fence. */ function code(node: any, _: Parent, state: NestedState, info: Info): string { - const nodeCodeBlockKeys = Object.keys(node).filter((k) => CODE_BLOCK_KEYS.includes(k)); + const nodeCodeBlockKeys = Object.entries(node).filter( + ([k, v]) => CODE_BLOCK_KEYS.includes(k) && v != null, + ); if (!nodeCodeBlockKeys.length) { return defaultHandlers.code(node, _, state, info); } diff --git a/packages/myst-to-md/tests/directives.yml b/packages/myst-to-md/tests/directives.yml index 5ea4833c0..f56124b64 100644 --- a/packages/myst-to-md/tests/directives.yml +++ b/packages/myst-to-md/tests/directives.yml @@ -217,6 +217,26 @@ cases: :lineno-start: 2 :meta: highlight-line="2" + 5+5 + print("hello world") + ``` + ``` + ```` + - title: code directive - null options + mdast: + type: root + children: + - type: code + lang: python + meta: null + showLineNumbers: null + value: |- + 5+5 + print("hello world") + ``` + ``` + markdown: |- + ````python 5+5 print("hello world") ```