1
0
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 b83c57b788ca5d1bea6055f86511b8e40a01f204 [formerly 3433556629]]]
Former-commit-id: ecb793c94c486f5b2d81f7886bd3b35b5ceda35a [formerly 386cc3db1b04854cecadbe16c6440619982752e0]
Former-commit-id: 5c75a42864a146e0d4b8bd20d71c05f7043cd79e
Former-commit-id: 3cd10cb68c
This commit is contained in:
Zack Scholl 2016-02-07 13:38:39 -05:00
parent 6acd0bc055
commit 48ce4b2ebf
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) html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
html2 := string(html) html2 := string(html)
r, _ := regexp.Compile("\\$(.*?)\\$") r, _ := regexp.Compile("\\$\\$(.*?)\\$\\$")
for _, s := range r.FindAllString(html2, -1) { 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{ c.HTML(http.StatusOK, "view.tmpl", gin.H{

View File

@ -45,9 +45,14 @@
<script> <script>
$( document ).ready(function() { $( document ).ready(function() {
var tex = document.getElementsByClassName("tex"); var texi = document.getElementsByClassName("texi");
Array.prototype.forEach.call(tex, function(el) { Array.prototype.forEach.call(texi, function(el) {
katex.render(el.getAttribute("data-expr"), 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 });
}); });
}); });