Skip to content

Commit

Permalink
fix(helpers): allow usage in ES6 modules fix for showdownjs#676
Browse files Browse the repository at this point in the history
* Fix for issue showdownjs#676

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

Co-authored-by: SyntaxRules <[email protected]>
  • Loading branch information
complynx and SyntaxRules authored Dec 23, 2021
1 parent 41cee10 commit ed51972
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ if (!showdown.hasOwnProperty('helper')) {
showdown.helper = {};
}

if (typeof this.document === 'undefined' && typeof this.window === 'undefined') {
var jsdom = require('jsdom');
this.window = new jsdom.JSDOM('', {}).window; // jshint ignore:line
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
Expand Down

0 comments on commit ed51972

Please sign in to comment.