1
0
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:
Zack Scholl 2016-02-07 13:38:39 -05:00
parent a4b98dd1c1
commit 3433556629
2 changed files with 14 additions and 5 deletions

View File

@ -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{

View File

@ -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 });
});
});