[英]How to render the quill js content using go buffalo framework
The options that i am aware of are, 我知道的选择是
Get the content of the quilljs from getContents
api which gives the JSON structure. 从
getContents
api获取quilljs的内容,该API提供了JSON结构。 I can post this to server and store it in server. 我可以将其发布到服务器并将其存储在服务器中。
Get the innerHTML of the div
which is passed to Quill editor and store it. 获取传递给Quill编辑器的
div
的innerHTML并将其存储。
Approach 1: 方法1:
While displaying it back I need to write the content in my buffalo template in a variable like 在显示回来的同时,我需要在水牛城模板中的变量中写入内容,例如
<script> var contentJSON = "<%= content %>"</script>
Then once the page loaded I need to set the contents like quillInstance.setContents(contentJSON)
然后,一旦页面加载完毕,我需要设置内容如
quillInstance.setContents(contentJSON)
Approach 2: 方法二:
Incase the request is compromised then the html may contain scripts unescaped. 如果请求遭到破坏,则html可能包含未转义的脚本。 So if I try like this
所以如果我这样尝试
c.Set("getContent", func(content string) template.HTML {
return template.HTML(html.EscapeString(content))
})
This escapes all the html entities. 这会转义所有html实体。 So all the div, styles introduced by quill js also gone with this.
因此,所有由Quill js引入的div,样式也都与此无关。 So the whole content looks just like a plain string.
因此,整个内容看起来就像一个纯字符串。
Whats the right approach in storing the content? 什么是存储内容的正确方法? I am looking for a way to get this rendered in the server.
我正在寻找一种方法来将此呈现在服务器中。
Finally i end with the following, 最后,我结束了以下内容,
Helpers: render.Helpers{
"quil_for": func(content string) template.HTML {
content = strings.ReplaceAll(content, "<script>", "<script>")
content = strings.ReplaceAll(content, "<a>", "<a>")
content = strings.ReplaceAll(content, "</a>", "</a>")
content = strings.ReplaceAll(content, "</script>", "</script>")
return template.HTML(content)
},
},
instead of this 代替这个
c.Set("getContent", func(content string) template.HTML {
return template.HTML(html.EscapeString(content))
})
This escapes only the script and the anchor tag and the res of html as it is. 这仅转义脚本和锚标记以及html的原样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.