Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quotes to frontmatter #20

Merged
merged 2 commits into from
Apr 6, 2021
Merged

Conversation

saswatamcode
Copy link
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
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!)

@@ -117,10 +118,18 @@ func (FormatFrontMatter) TransformFrontMatter(_ SourceContext, frontMatter map[s
// 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
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>
Copy link
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