-
Notifications
You must be signed in to change notification settings - Fork 56
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 markdown file support in partials #77
Conversation
Well, It makes sense we need to include a markdown within HTML output in some cases. But the output itself is already rendered HTML and it means, the |
Additionally, doing |
I agree with Yonghwan. I think it’s ok to say, if you want to render a partial as md you should use md extension.
I know support auto extensions, and technically this constitutes a breaking change; but i would be surprised if there are a lot of users using a md partial with no extension given in the partial call.
I wrote that feature, and didn’t realize you could call md partials without the extension and it would be smart enough md it.
I’m buffalo at some point there has to be something that looks up the file from disk to feed the feeder, so at that point you should have the extension anyway. I think.
Don’t quote me. I just woke up. :)
…On Nov 21, 2018, 6:24 AM -0500, Yonghwan SO ***@***.***>, wrote:
Additionally, doing JSEscapeString() is a solution for embedding an HTML within Javascript. So for markdown, it should be rendered before JS handling (with faking extension after render) or it needs another checking if ct contains javascript and in this case, it also needs to be escaped.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Markdown partials without extension are somewhat covered by buffalo: https://github.com/gobuffalo/buffalo/blob/7dc6819f6cce0150869218165c210c445c3f3d93/render/template.go#L46 |
Added some changes. |
Yes, basically. And for getting into the block of Anyway, if it has |
I will test the layouts, thanks.
Can you explain this a bit more? |
When there is a
I guess the test case below shows you what it does, even though the example is not perfact and the Lines 218 to 232 in 2171edb
For this PR, if the markdown partial is used with javascript output, as something like following example, and there are some quotation marks inside of rendered partial, prettyAlert("<%= partial("warning_message.md" %>") and You **cannot** use "markdown" partial *without* this PR! |
This will JS escape for all files except for .js
I added a PR to this branch so please check the PR. #78. |
Thanks for the PR 👍 The only remaining point is whether we need to escape partials in a situation like this: <!-- sample.html -->
<h1>Some HTML with JS</h1>
<script>
console.log("<%= partial("someText.txt") %>")
</script>
I don't know a simple way to fix this and I'm not sure if we should escape it. |
Yes! that is a self-made code-injection attack! right? haha... I don't think those cases are not common but if some users still want to similar things, then the user can choose some alternatives like... using a step-by-step approach:
This code will not work fine since there are some problems like type mismatch, type conversion, and so on. but if we... finally should handle this problem, I think this approach is one of the possibles. |
As this is out of the scope for this PR, I extracted this to #79 for further discussion, but as I already stated, I don't think this is something needed to be fixed. @sio4 Thanks again for the help |
I also think so. |
This is a fix for gobuffalo/docs#404, but not necessarily a good one:
What is bad?
In contrast to the js support in
partial_helper.go#47
, the markdown support activates if the content type includesmarkdown
or if the file ends in.md
(JS support requires both to be true). This is inconsistent and might lead to confusion.Why did I still do it this way?
Concluding from my tests, buffalo doesn't set a
markdown
content type but usestext/html
. I could not yet find the place to change this in buffalo. I'm not sure if buffalo can change the content type for markdown files as r.HTML seems to define it on initialization where the file type might not yet be clear: https://gobuffalo.io/en/docs/rendering#automatic-extensionsSolution
To be honest, I don't think this really is a big deal. If someone can give me some pointers on how to fix it in buffalo though, I'd be happy to give it a try and make this fix a bit better.