“大规模杀伤性武器”网络 Markdown 和如何实现图像上传功能
我正在开发一个使用 MarkDown 和 WMD javascript 工具的网站,该工具目前可以满足已经托管的图像的需求,但我希望能够根据 Stack Overflow 在 WMD 中提供图像上传工具,但我不知道怎么办呢?
有谁知道如何实施?我的网站正在使用 ASP.NET MVC 进行开发,我对上传图像等的服务器端很满意,但如何将其挂接到 javascript WMD 编辑器(以及可能的 AJAX 元素)中是我需要考虑的问题。我被困住了。
I'm developing a site that uses MarkDown and WMD javascript tools which currently caters for images that are already hosted, but I'd like to be able to offer an image upload facility within WMD, as per Stack Overflow, but don't know how to go about this.
Does anyone know how this can be implemented? My site is being developed, using ASP.NET MVC, and I'm fine with the server side of uploading an image etc, but it's how to hook this into the the javascript WMD editor (and potentially the AJAX element of it) that I'm stuck on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们最近发布了 WMD 的重构版本;您可以在 http://code.google.com/p/pagedown/ 找到它。
Stack Overflow 使用的所有非标准内容现在都通过插件挂钩进行,其中包括我们的文件上传器。所以你可以使用相同的钩子来实现这一点。查看文档; “连接”部分归结为:
至于实际的上传,我们目前使用一个非常丑陋的解决方案,其工作原理如下:
target
属性设置为隐藏的 iframe ,因此提交表单不会将您带到不同的页面。window.parent
,因为我们必须突破 iframe - 请注意,这需要上传 URL与页面具有相同的起源!)以及新创建图像的地址。如果您打算以类似的方式实现这一点,请查看 Meta Stack Overflow 上的这篇文章,涉及可能出现的令人讨厌的 Chrome 错误及其解决方法。
We have recently released our refactored version of WMD; you can find it at http://code.google.com/p/pagedown/.
Everything that is non-standard about Stack Overflow's usage now happens via plugin hooks, and this includes our file uploader. So you can just use the same hook to implement this. Have a look at the documentation; the "hooking up" part boils down to this:
As to the actual uploading, we currently use a pretty ugly solution that works like this:
target
attribute set to a hidden iframe, so submitting the form doesn't send you to a different page.window.parent
, since we have to break out of the iframe – note that this requires the upload URL to have the same origin as the page!) with the address of the newly created image.If you're going to implement this in a similar fashion, take a look at this post on Meta Stack Overflow regarding a nasty Chrome bug that can appear, and a workaround for it.