Skip to content

Commit d2e7fbb

Browse files
committed
Merge branch 'dev-v0.3.0'
Conflicts: README.md
2 parents c39b6a9 + d727ea3 commit d2e7fbb

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
Redmine LaTeX MathJax Plugin
2-
============================
1+
Redmine LaTeX MathJax Macro Plugin
2+
==================================
3+
34
This is a simple little plugin which allows mathematical notation to be used within Redmine.
45

6+
Requirements
7+
------------
8+
9+
Redmine 3.0.x or 3.1.x.
10+
Other version are not tested but may work.
11+
512
Installation
613
------------
714
1. Download archive and extract to /your/path/to/redmine/plugins/
@@ -13,12 +20,20 @@ Login to Redmine and go to Administration->Plugins. You should now see 'Redmine
1320

1421
Usage
1522
------------
16-
Anywhere on a wiki page write for inline formulas:
23+
Anywhere on a wiki or issue page write for formulas:
1724

1825
{{mj(\sum_i x_i$)}}
1926

20-
Hit 'Preview' or 'Save' to make the notation show up.
27+
or a multiline MathJax Syntax:
28+
29+
{{mj
30+
P_{POWER} =
31+
\cfrac
32+
{U_{POWER}}
33+
{I_{POWER}}
34+
}}
2135

36+
Hit 'Preview' or 'Save' to let them show up.
2237

2338
FAQ
2439
------------

init.rb

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
description 'Employ MathJax in all settings: wiki, issues, or every page.'
99
url 'https://github.com/vDorst/redmine_latex_mathjax'
1010
author_url 'https://github.com/vDorst'
11-
version '0.2.0'
11+
version '0.3.0'
1212

1313
Redmine::WikiFormatting::Macros.register do
14-
desc = "MathJax Macro: Usage: {{mj( MathJax Syntax )}}"
15-
macro :mj, :parse_args => false do |obj, args|
16-
out = MathJaxEmbedMacro.mj_macro(obj, args)
14+
desc "MathJax Macro:\n\n" +
15+
"Usage:\n"+
16+
"{{mj( single line MathJax Syntax )}}\n\n" +
17+
"{{mj\nMulti line\nMathJax Syntax\n}}"
18+
macro :mj, :parse_args => false do |obj, args, text|
19+
out = MathJaxEmbedMacro.mj_macro(obj, args, text)
1720
end
1821
end
1922
end
@@ -23,15 +26,36 @@ class MathJaxEmbedMacro
2326
@@delimiter = '~~~'
2427
# Modify URL to MathJax.
2528
@@url = 'https://cdn.mathjax.org/mathjax/latest/MathJax.js'
26-
def self.mj_macro(obj, arg)
27-
raise "Usage: {{mj( MathJax Syntax )}}" unless arg.length >= 1
28-
out = "#@@delimiter #{arg} #@@delimiter".html_safe
29+
def self.mj_error(text)
30+
return "<span id=\"errorExplanation\"><strong>MathJaxMacro:</strong> #{text}</span>".html_safe
31+
end
32+
def self.mj_macro(obj, arg, text)
33+
## Check any argument is given
34+
if ((text == nil) && (arg.length == 0))
35+
return "<div id=\"errorExplanation\"><strong>MathJaxMacro:</strong> Usage:<ul><li><stong>Argument only</strong>: only single line MathJax Syntax</li>{{mj( MathJax Syntax )}}<li>Blocktext only: Multiline MathJax Syntax</li>{{mj<br/>Multi-<br/>line<br/>}}</ul></div>".html_safe
36+
end
37+
## Check if both argument are given
38+
if ((text != nil) && (arg.length > 0))
39+
return self.mj_error("Usage: Don\'t mix argument and blocktext!")
40+
end
41+
# Use text is arg == nil
42+
if (text != nil)
43+
arg = text
44+
end
45+
# Check argument length in Argument Mode
46+
if (arg != nil) && (arg.length < 1)
47+
return self.mj_error("Input must be atlease 1 characet long.")
48+
end
49+
# Check for illegal charaters.
50+
if arg =~ /[<>]/
51+
return self.mj_error("Illegal characters found! Don\'t using < or >")
52+
end
53+
return "#@@delimiter #{arg} #@@delimiter".html_safe
2954
end
3055
def self.delimiter()
3156
return @@delimiter
3257
end
3358
def self.URLToMathJax()
3459
return @@url
3560
end
36-
end
37-
61+
end

0 commit comments

Comments
 (0)