Skip to content

Commit 88046cd

Browse files
author
runarberg
committed
Make ascii2mathml an optional dependency
Closes #13
1 parent 216758f commit 88046cd

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,24 @@ function makeMath_block(open, close) {
213213
};
214214
}
215215

216-
function makeMathRenderer(options) {
216+
function makeMathRenderer(renderingOptions) {
217217
if (ascii2mathml === null) {
218-
ascii2mathml = require('ascii2mathml');
218+
try {
219+
ascii2mathml = require('ascii2mathml');
220+
} catch (e) {
221+
return renderingOptions && renderingOptions.display === 'block' ?
222+
function(tokens, idx) {
223+
return '<div class="math block">' + tokens[idx].content + '</div>';
224+
} :
225+
function(tokens, idx) {
226+
return '<span class="math inline">' + tokens[idx].content + '</span>';
227+
};
228+
}
219229
}
220-
var mathml = ascii2mathml(Object.assign({}, options));
221230

222-
return options && options.display === 'block' ?
231+
var mathml = ascii2mathml(Object.assign({}, renderingOptions));
232+
233+
return renderingOptions && renderingOptions.display === 'block' ?
223234
function(tokens, idx) {
224235
return mathml(tokens[idx].content) + '\n';
225236
} :

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"url": "https://github.com/runarberg/markdown-it-math/issues"
3434
},
3535
"homepage": "https://github.com/runarberg/markdown-it-math",
36-
"dependencies": {
37-
"ascii2mathml": "^0.5.2"
36+
"optionalDependencies": {
37+
"ascii2mathml": "^0.5.3"
3838
},
3939
"devDependencies": {
4040
"babelify": "^6.3.0",

0 commit comments

Comments
 (0)