summaryrefslogtreecommitdiffstats
path: root/_plugins/singledollar.rb
diff options
context:
space:
mode:
authorJustin Gassner <justin.gassner@mailbox.org>2023-09-12 07:36:33 +0200
committerJustin Gassner <justin.gassner@mailbox.org>2024-01-13 20:41:27 +0100
commit777f9d3fd8caf56e6bc6999a4b05379307d0733f (patch)
treedc42d2ae9b4a8e7ee467f59e25c9e122e63f2e04 /_plugins/singledollar.rb
downloadsite-777f9d3fd8caf56e6bc6999a4b05379307d0733f.tar.zst
Initial commit
Diffstat (limited to '_plugins/singledollar.rb')
-rw-r--r--_plugins/singledollar.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/_plugins/singledollar.rb b/_plugins/singledollar.rb
new file mode 100644
index 0000000..fe665ab
--- /dev/null
+++ b/_plugins/singledollar.rb
@@ -0,0 +1,19 @@
+# https://gist.github.com/sp301415/db9f7bee03bda483aa2ca7c0ca92fbfa
+
+require 'kramdown/parser/kramdown'
+require 'kramdown-parser-gfm'
+
+class Kramdown::Parser::GFMKatex < Kramdown::Parser::GFM
+ # Override inline math parser
+ @@parsers.delete(:inline_math)
+
+ INLINE_MATH_START = /(\$+)([^\$]+)(\$+)/m
+
+ def parse_inline_math
+ start_line_number = @src.current_line_number
+ @src.pos += @src.matched_size
+ @tree.children << Element.new(:math, @src.matched[1..-2], nil, category: :span, location: start_line_number)
+ end
+
+ define_parser(:inline_math, INLINE_MATH_START, '\$')
+end