From 48dd51960f8409c06b7f5439c237db55f611107d Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Sat, 3 Apr 2021 18:15:27 +0100 Subject: [PATCH] fix additional javascript problems, and try to make the highlighting more attractive --- config.toml | 5 +++-- content/post/its-alive.md | 10 +++++----- content/post/nextcloud-caldav-error.md | 5 ++--- static/js/math-code.js | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 static/js/math-code.js diff --git a/config.toml b/config.toml index e07d9c9..26fd552 100644 --- a/config.toml +++ b/config.toml @@ -16,8 +16,9 @@ paginate = 10 [params] subtitle = "A Journal" brand = "\"\"/
Ipse Solus
" - highlightjs = "androidstudio" - highlightjs_extra_languages = ["yaml", "xml-dtd"] + highlightjs = "tomorrow" + highlightjs_extra_languages = ["yaml"] + custom_js = ["js/math-code.js"] dateFormat = "02 Jan 2006, 15:04" [menu] diff --git a/content/post/its-alive.md b/content/post/its-alive.md index fcd7c6a..25f83fa 100644 --- a/content/post/its-alive.md +++ b/content/post/its-alive.md @@ -10,11 +10,11 @@ Here's a snippet of Go. ```go func str2int(strnum string) int { - i, err := strconv.Atoi(strnum) - if err != nil { - return 9999 - } - return i + i, err := strconv.Atoi(strnum) + if err != nil { + return 9999 + } + return i } ``` diff --git a/content/post/nextcloud-caldav-error.md b/content/post/nextcloud-caldav-error.md index f47b6ef..fe32392 100644 --- a/content/post/nextcloud-caldav-error.md +++ b/content/post/nextcloud-caldav-error.md @@ -10,7 +10,7 @@ Unfortunately, out of the box, it wasn't working. I tried all sorts of suggestio Then, after a day of staring blankly at the problem, I suddenly realized what was wrong. There was a simple `regex` typo in the htaccess configuration that came from nextcloud. Let's see if you can see the difference. Here's what nextcloud gives you: -```xml +```apache RewriteEngine on RewriteCond %{HTTP_USER_AGENT} DavClnt @@ -27,7 +27,7 @@ Then, after a day of staring blankly at the problem, I suddenly realized what wa and here is what I ended up running successfully with: -```xml +```apache RewriteEngine on RewriteCond %{HTTP_USER_AGENT} DavClnt @@ -45,4 +45,3 @@ and here is what I ended up running successfully with: Can you see it? Hint: RewriteRules require leading forward-slashes to work. But REGEX rules require leading back-slashes to escape special characters in uris. So, I had to change this `^\.` to this `^/\.` and everything started working. Hopefully, for those of you into self-hosting, this will save you the hours of pain and suffering it cost me. - diff --git a/static/js/math-code.js b/static/js/math-code.js new file mode 100644 index 0000000..4616a27 --- /dev/null +++ b/static/js/math-code.js @@ -0,0 +1,20 @@ +(function() { + var i, text, code, codes = document.getElementsByTagName('code'); + for (i = 0; i < codes.length;) { + code = codes[i]; + if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) { + text = code.textContent; + if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) { + text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)'); + code.textContent = text; + } + if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) || + /^\$(.|\s)+\$$/.test(text) || + /^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) { + code.outerHTML = code.innerHTML; // remove + continue; + } + } + i++; + } + })(); \ No newline at end of file