mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Added inline math
Former-commit-id: 16d1a0de448a447cdae94602c889bd3752af2a58 [formerly 578c58bd645802094d1bb45674a7c39ca09c0279] [formerly 7087210383074b49a2298b36f3ffa284cb942d28 [formerly 3433556629
]]
Former-commit-id: ecb793c94c486f5b2d81f7886bd3b35b5ceda35a [formerly 386cc3db1b04854cecadbe16c6440619982752e0]
Former-commit-id: 5c75a42864a146e0d4b8bd20d71c05f7043cd79e
This commit is contained in:
parent
921e5a0ce5
commit
3cd10cb68c
@ -65,9 +65,13 @@ func renderMarkdown(c *gin.Context, title string) {
|
||||
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
|
||||
html2 := string(html)
|
||||
|
||||
r, _ := regexp.Compile("\\$(.*?)\\$")
|
||||
r, _ := regexp.Compile("\\$\\$(.*?)\\$\\$")
|
||||
for _, s := range r.FindAllString(html2, -1) {
|
||||
html2 = strings.Replace(html2, s, "<div class='tex' data-expr='"+s[1:len(s)-1]+"'></div>", 1)
|
||||
html2 = strings.Replace(html2, s, "<div class='texp' data-expr='"+s[2:len(s)-2]+"'></div>", 1)
|
||||
}
|
||||
r, _ = regexp.Compile("\\$(.*?)\\$")
|
||||
for _, s := range r.FindAllString(html2, -1) {
|
||||
html2 = strings.Replace(html2, s, "<div class='texi' data-expr='"+s[1:len(s)-1]+"'></div>", 1)
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "view.tmpl", gin.H{
|
||||
|
@ -45,9 +45,14 @@
|
||||
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
var tex = document.getElementsByClassName("tex");
|
||||
Array.prototype.forEach.call(tex, function(el) {
|
||||
katex.render(el.getAttribute("data-expr"), el);
|
||||
var texi = document.getElementsByClassName("texi");
|
||||
Array.prototype.forEach.call(texi, function(el) {
|
||||
katex.render(el.getAttribute("data-expr"), el, { displayMode: true });
|
||||
});
|
||||
|
||||
var texp = document.getElementsByClassName("texp");
|
||||
Array.prototype.forEach.call(texp, function(el) {
|
||||
katex.render(el.getAttribute("data-expr"), el, { displayMode: false });
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user