Skip to content

Add quotes to frontmatter - #20

Merged
bwplotka merged 2 commits into
bwplotka:masterfrom
saswatamcode:add-quote
Apr 6, 2021
Merged

bwplotka merged 2 commits into
bwplotka:masterfrom
saswatamcode:add-quote

Conversation

@saswatamcode

Copy link
Copy Markdown
Collaborator

Currently, mdox removes all quotes from frontmatter values. But in case a value contains a semicolon, there might be yaml parsing issues in framworks like hugo. An example of this can be found here.
Before, this example would be outputted as,

title: Components:

This fix ensures that if a value has a semicolon, quotes would be preserved like so,

title: "Components:"

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can we have that tested too? 🤗

Also, I would quote all strings then! (Consistency!)

Comment thread pkg/mdformatter/mdformatter.go Outdated
// Loop through all nested keys.
_, _ = fmt.Fprintf(b, "\n%v:", k)
for key, val := range frontMatterMap {
if v, ok := val.(string); ok && strings.Contains(v, ":") {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: check if string and then always use strconv.Quote function? 🤗

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
@saswatamcode
saswatamcode requested a review from bwplotka March 29, 2021 08:43

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks 💪🏽

@bwplotka
bwplotka merged commit 59e9130 into bwplotka:master Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址