Skip to content

Commit

Permalink
⌨️ Do not export code block options when undefined (#1721)
Browse files Browse the repository at this point in the history
Co-authored-by: Franklin Koch <franklinwkoch@gmail.com>
  • Loading branch information
rowanc1 and fwkoch authored Jan 6, 2025
1 parent 0d82810 commit 3950dca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/wicked-gifts-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-to-md": patch
---

Do not have code block options exported when they are null
4 changes: 3 additions & 1 deletion packages/myst-to-md/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions packages/myst-to-md/tests/directives.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```
Expand Down

0 comments on commit 3950dca

Please sign in to comment.