2019-10-14 09:17:30 -04:00
|
|
|
/* global MathJax */
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-04-06 07:45:56 -04:00
|
|
|
define(['../base'], function(App) {
|
2019-03-18 07:59:46 -04:00
|
|
|
return App.directive('mathjax', function($compile, $parse) {
|
2019-03-18 06:24:54 -04:00
|
|
|
return {
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
if (!(MathJax && MathJax.Hub)) return
|
|
|
|
|
2019-03-18 07:59:46 -04:00
|
|
|
// Allowing HTML can be unsafe unless using something like
|
|
|
|
// `ng-bind-html` because of potential Angular XSS via {{/}}
|
|
|
|
if (!$parse(attrs.mathjaxAllowHtml)(scope)) {
|
|
|
|
const mathJaxContents = element.html()
|
|
|
|
const nonBindableEl = $compile('<span ng-non-bindable></span>')({})
|
|
|
|
element.html('').append(nonBindableEl)
|
|
|
|
nonBindableEl.html(mathJaxContents)
|
|
|
|
}
|
2019-03-18 06:24:54 -04:00
|
|
|
|
|
|
|
if (attrs.delimiter !== 'no-single-dollar') {
|
|
|
|
const inlineMathConfig =
|
|
|
|
MathJax.Hub.config && MathJax.Hub.config.tex2jax.inlineMath
|
|
|
|
const alreadyConfigured = _.find(
|
|
|
|
inlineMathConfig,
|
|
|
|
c => c[0] === '$' && c[1] === '$'
|
2018-11-05 05:06:39 -05:00
|
|
|
)
|
2019-03-18 06:24:54 -04:00
|
|
|
|
|
|
|
if (!alreadyConfigured) {
|
|
|
|
MathJax.Hub.Config({
|
|
|
|
tex2jax: {
|
|
|
|
inlineMath: inlineMathConfig.concat([['$', '$']])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2019-03-18 06:24:54 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
MathJax.Hub.Queue(['Typeset', MathJax.Hub, element.get(0)])
|
|
|
|
}, 0)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-03-18 06:24:54 -04:00
|
|
|
})
|
|
|
|
})
|