Merge pull request #629 from pulsar-edit/markdown-preview/fix-yaml-frontmatter

[markdown-preview]: Support for nested table objects in Yaml Frontmatter
This commit is contained in:
confused_techie 2023-07-25 16:26:47 -07:00 committed by GitHub
commit 76e358bc60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 4 deletions

View File

@ -107,7 +107,14 @@ function renderYamlTable (variables) {
const markdownRows = [
entries.map(entry => entry[0]),
entries.map(entry => '--'),
entries.map(entry => entry[1])
entries.map((entry) => {
if (typeof entry[1] === "object" && !Array.isArray(entry[1])) {
// Remove all newlines, or they ruin formatting of parent table
return marked.parse(renderYamlTable(entry[1])).replace(/\n/g,"");
} else {
return entry[1];
}
})
]
return (

View File

@ -15,7 +15,7 @@
"fs-plus": "^3.0.0",
"marked": "5.0.3",
"underscore-plus": "^1.0.0",
"yaml-front-matter": "^4.0.0"
"yaml-front-matter": "^4.1.1"
},
"devDependencies": {
"temp": "^0.8.1"

View File

@ -3,6 +3,8 @@ variable1: value1
array:
- foo
- bar
object:
key: value2
---
## File.markdown

View File

@ -338,12 +338,12 @@ end\
[...preview.element.querySelectorAll('table th')].map(
el => el.textContent
)
).toEqual(['variable1', 'array'])
).toEqual(['variable1', 'array', 'object', 'key'])
expect(
[...preview.element.querySelectorAll('table td')].map(
el => el.textContent
)
).toEqual(['value1', 'foo,bar'])
).toEqual(['value1', 'foo,bar', 'keyvalue2', 'value2'])
})
})
})