Skip to content

Add quotes to frontmatter#20

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

Add quotes to frontmatter#20
bwplotka merged 2 commits intobwplotka: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>
Copy link
Copy Markdown
Owner

@bwplotka bwplotka left a comment

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!)

// 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
Copy link
Copy Markdown
Owner

@bwplotka bwplotka left a comment

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