-
Notifications
You must be signed in to change notification settings - Fork 68
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
Conversation
There was a problem hiding this 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!
std/markdown.joke
Outdated
@@ -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`) |
There was a problem hiding this comment.
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)"
std/markdown.joke
Outdated
2 "convertStringOpts(s, opts)"}} | ||
([^String s]) | ||
([^String s ^Object opts])) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
std/markdown/markdown_native.go
Outdated
if !ok { | ||
return def | ||
} | ||
val, ok := entry.(Boolean) |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😬
Use Map parameter type for simplified type checking. Refactor duplicate common rendering logic;
Ok... I think I've fixed all those issues. Thanks for your help! |
@wnh Looks great! Thanks a lot! |
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!