2020-06-23 08:45:38 +00:00
|
|
|
import _ from 'lodash'
|
2019-10-14 13:17:30 +00:00
|
|
|
/* global MathJax */
|
2018-11-05 10:06:39 +00:00
|
|
|
|
2020-05-19 09:02:56 +00:00
|
|
|
import App from '../base'
|
2019-03-18 10:24:54 +00:00
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
export default App.directive('mathjax', function ($compile, $parse) {
|
2020-05-19 09:02:56 +00:00
|
|
|
return {
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
if (!(MathJax && MathJax.Hub)) return
|
2019-03-18 10:24:54 +00:00
|
|
|
|
2020-05-19 09:02:56 +00: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 10:06:39 +00:00
|
|
|
|
2020-05-19 09:02:56 +00:00
|
|
|
if (!alreadyConfigured) {
|
|
|
|
MathJax.Hub.Config({
|
|
|
|
tex2jax: {
|
2021-04-27 07:52:58 +00:00
|
|
|
inlineMath: inlineMathConfig.concat([['$', '$']]),
|
|
|
|
},
|
2020-05-19 09:02:56 +00:00
|
|
|
})
|
|
|
|
}
|
2019-03-18 10:24:54 +00:00
|
|
|
}
|
2020-05-19 09:02:56 +00:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
MathJax.Hub.Queue(['Typeset', MathJax.Hub, element.get(0)])
|
|
|
|
}, 0)
|
2021-04-27 07:52:58 +00:00
|
|
|
},
|
2020-05-19 09:02:56 +00:00
|
|
|
}
|
2019-03-18 10:24:54 +00:00
|
|
|
})
|