fix(helpers): allow usage in ES6 modules fix for #676

* Fix for issue #676

This will check for situations when this is undefined, eg ES6 module wrapper

Co-authored-by: SyntaxRules <devyn.stott@gmail.com>
This commit is contained in:
Daniel 2021-12-23 22:10:23 +03:00 committed by GitHub
parent 41cee10659
commit ed51972315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,11 +6,15 @@ if (!showdown.hasOwnProperty('helper')) {
showdown.helper = {};
}
if (typeof this.document === 'undefined' && typeof this.window === 'undefined') {
if (typeof this === 'undefined' && typeof window !== 'undefined') {
showdown.helper.document = window.document;
} else {
if (typeof this.document === 'undefined' && typeof this.window === 'undefined') {
var jsdom = require('jsdom');
this.window = new jsdom.JSDOM('', {}).window; // jshint ignore:line
}
showdown.helper.document = this.window.document;
}
showdown.helper.document = this.window.document;
/**
* Check if var is string