mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Added inline math
This commit is contained in:
parent
a4b98dd1c1
commit
3433556629
@ -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