-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
impletement supply an option for user to switch for the inline MathJa…
…x expression #283
- Loading branch information
Showing
10 changed files
with
137 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
define([ | ||
], | ||
function() { | ||
var marked = require("marked"); | ||
var options = store.get('Markdown') || {}; | ||
|
||
var InlineLexer = marked.InlineLexer; | ||
|
||
var customRules = { | ||
stronghighlight: /^==([^=]+)==/, | ||
underline: /^_([^_]+)_/ | ||
}; | ||
|
||
var inlineMathRegEx = /^ *(split)([\s\S]*?[^\$])\1(?!\$)/; | ||
if (options.dollarSign) { | ||
customRules.math = replace(inlineMathRegEx) | ||
('split', /\${3,3}|\${1,1}/) | ||
(); | ||
} | ||
|
||
|
||
function replace(regex, opt) { | ||
regex = regex.source; | ||
opt = opt || ''; | ||
return function self(name, val) { | ||
if (!name) return new RegExp(regex, opt); | ||
val = val.source || val; | ||
val = val.replace(/(^|[^\[])\^/g, '$1'); | ||
regex = regex.replace(name, val); | ||
return self; | ||
}; | ||
} | ||
|
||
function merge(obj) { | ||
var i = 1 | ||
, target | ||
, key; | ||
|
||
for (; i < arguments.length; i++) { | ||
target = arguments[i]; | ||
for (key in target) { | ||
if (Object.prototype.hasOwnProperty.call(target, key)) { | ||
obj[key] = target[key]; | ||
} | ||
} | ||
} | ||
|
||
return obj; | ||
} | ||
|
||
InlineLexer.rules.normal = merge({}, InlineLexer.rules.normal, customRules); | ||
InlineLexer.rules.gfm = merge({}, InlineLexer.rules.gfm, customRules); | ||
InlineLexer.rules.breaks = merge({}, InlineLexer.rules.breaks, customRules); | ||
|
||
window.ee.on('preferences.markdown.change', function(options) { | ||
var rules = InlineLexer.rules; | ||
|
||
if (options.dollarSign) { | ||
customRules.math = replace(inlineMathRegEx) | ||
('split', /\${3,3}|\${1,1}/) | ||
(); | ||
} else { | ||
customRules.math = replace(inlineMathRegEx) | ||
('split', /\${3,3}/) | ||
(); | ||
} | ||
|
||
if (options.gfm) { | ||
InlineLexer.rules.gfm = merge({}, rules.gfm, customRules); | ||
} | ||
|
||
if (options.breaks) { | ||
InlineLexer.rules.breaks = merge({}, rules.breaks, customRules); | ||
} | ||
|
||
window.ee.emit('preferences.markdown.change.after'); | ||
}); | ||
|
||
return InlineLexer; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters