From d4b751a71727ad9c41526abf988e11c9ce980af4 Mon Sep 17 00:00:00 2001 From: Tadej Novak Date: Sun, 15 Jan 2017 10:24:24 +0100 Subject: [PATCH] Support older versions of Discourse --- assets/javascripts/tex_dialect.js | 69 +++++++++++++++++++++++++++++++ plugin.rb | 2 + 2 files changed, 71 insertions(+) create mode 100644 assets/javascripts/tex_dialect.js diff --git a/assets/javascripts/tex_dialect.js b/assets/javascripts/tex_dialect.js new file mode 100644 index 0000000..e62e610 --- /dev/null +++ b/assets/javascripts/tex_dialect.js @@ -0,0 +1,69 @@ +(function() { + // Don't bother with this code if the new dialect system is present + if (Discourse.dialect_deprecated) { return; } + + Discourse.Dialect.inlineBetween({ + start: '\\(', + stop: '\\)', + rawContents: true, + emitter: function (contents) { + return '\\(' + contents + '\\)'; + } + }); + + Discourse.Dialect.inlineBetween({ + start: '\\[', + stop: '\\]', + rawContents: true, + emitter: function (contents) { + return '\\[' + contents + '\\]'; + } + }); + + Discourse.Dialect.inlineBetween({ + start: '$$', + stop: '$$', + rawContents: true, + emitter: function (contents) { + return '$$' + contents + '$$'; + } + }); + + + Discourse.Dialect.inlineBetween({ + start: '$', + stop: '$', + rawContents: true, + emitter: function (contents) { + return '$' + contents + '$'; + } + }); + + Discourse.Dialect.inlineRegexp({ + start: '\\begin', + matcher: /(\\begin{[\S\s]+})([\S\s]*)(\\end{[\S\s]+})/, + emitter: function (matches) { + return matches[0]; + } + }); + + //these last two are to make asciimath support possible + + Discourse.Dialect.inlineBetween({ + start: 'ˊˊ', + stop: 'ˊˊ', + rawContents: true, + emitter: function (contents) { + return 'ˊˊ' + contents + 'ˊˊ'; + } + }); + + Discourse.Dialect.inlineBetween({ + start: 'ˊ', + stop: 'ˊ', + rawContents: true, + emitter: function (contents) { + return 'ˊ' + contents + 'ˊ'; + } + }); +})(); diff --git a/plugin.rb b/plugin.rb index 60c8024..e9f45ac 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,3 +1,5 @@ # name: MathJax support for Discourse # version: 0.4.1 # authors: Sam Saffron, Kasper Peulen + +register_asset('javascripts/tex_dialect.js', :server_side)