Skip to content

Commit

Permalink
formatter bug fix (markdoc#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix-stripe authored Sep 22, 2022
1 parent f1e491e commit 6542b32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Markdoc is a **Markdown**-based \`syntax\` and _toolchain_ for creating ~~custom
![Alt](/image)
{% callout #id .class .class2 a="check" b={"e":{f: 5}} c=8 d=[1, "2",true] %}
{% callout #id .class .class2 a="check" b={"e":{"with space": 5}} c=8 d=[1, "2",true] %}
Markdoc is open-source—check out it's [source](http://github.com/markdoc/markdoc) to see how it works.
{% /callout %}
Expand Down Expand Up @@ -52,7 +52,14 @@ Markdoc is a **Markdown**-based \`syntax\` and _toolchain_ for creating ~~custom
![Alt](/image)
{% callout #id .class .class2 a="check" b={e: {f: 5}} c=8 d=[1, "2", true] %}
{% callout
#id
.class
.class2
a="check"
b={e: {"with space": 5}}
c=8
d=[1, "2", true] %}
Markdoc is open-source—check out it's [source](http://github.com/markdoc/markdoc) to see how it works.
{% /callout %}
Expand Down
5 changes: 4 additions & 1 deletion src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ function formatScalar(v: Value): string {
return (
'{' +
Object.entries(v)
.map(([key, value]) => `${key}: ${formatScalar(value)}`)
.map(
([key, value]) =>
`${isIdentifier(key) ? key : `"${key}"`}: ${formatScalar(value)}`
)
.join(SEP) +
'}'
);
Expand Down

0 comments on commit 6542b32

Please sign in to comment.