Skip to content

Add control over markdown rendering options #487

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

Merged
merged 3 commits into from
Jul 17, 2023

Conversation

wnh
Copy link
Contributor

@wnh wnh commented Jul 16, 2023

I've been building a little static site generator with joker and was missing the ability to turn off the hard line wraps. I've added flags for the other rendering options just for good measure.

I hope the style is ok. I'm not sure what the right pattern is for throwing an exception from the native Go code when a type is wrong. If there is a nicer way I'll happily update it.

Thanks!

Copy link
Owner

@candid82 candid82 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 overall, I made a few suggestions on how to improve some things. Thanks!

@@ -4,7 +4,14 @@
markdown)

(defn ^String convert-string
"Returns the HTML rendering of Markdown string s"
"Returns the HTML rendering of Markdown string s `opts` is an optional map of boolean rendering options (all default to tru to `true`)
Copy link
Owner

Choose a reason for hiding this comment

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

Missing . after string s. Also typo: to tru. Finally, there is no markdown support in docstrings, so "`" should not be used. So something like:

"Returns the HTML rendering of Markdown string s. opts is an optional map of boolean rendering options (all default to true)"

2 "convertStringOpts(s, opts)"}}
([^String s])
([^String s ^Object opts]))
Copy link
Owner

Choose a reason for hiding this comment

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

You can specify Map type directly here, which will simplify the implementation: [^String s ^Map opts]. See joker.http/send for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I probably should have looked harder for an example of that

if !ok {
return def
}
val, ok := entry.(Boolean)
Copy link
Owner

Choose a reason for hiding this comment

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

Please use EnsureObjectIsBoolean here for uniformity.

if flag := getKeywordFlag(options, "with-unsafe?", true); flag {
renderOptions = append(renderOptions, html.WithUnsafe())
}
md := goldmark.New(
Copy link
Owner

Choose a reason for hiding this comment

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

This is largely a duplication of convertString. Can you refactor the code to avoid duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I copied the whole method I definitely told myself I would need to go back and fix the duplication. I guess I just got a little excited 😬

wnh added 2 commits July 17, 2023 08:42
Use Map parameter type for simplified type checking.
Refactor duplicate common rendering logic;
@wnh
Copy link
Contributor Author

wnh commented Jul 17, 2023

Ok... I think I've fixed all those issues. Thanks for your help!

@wnh wnh requested a review from candid82 July 17, 2023 16:02
@candid82
Copy link
Owner

@wnh Looks great! Thanks a lot!

@candid82 candid82 merged commit d79a18f into candid82:master Jul 17, 2023
@wnh wnh deleted the markdown-feature-options branch July 17, 2023 19:09
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