0

I am trying to import editormd like this:

import { editormd } from "../../../content/static/mdeditor/js/editormd";

$(function () {
  var testEditormdView;
  testEditormdView = editormd.markdownToHTML("my-element-id", {
    emoji: false,
    taskList: true,
    tex: true,
    flowChart: true,
    sequenceDiagram: true,
  });
});

while using Node. I'm not sure if it is even importable.

The file (editormd.js) starts off like this:

;(function(factory) {
    "use strict";
    
    // CommonJS/Node.js
    if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
    { 
        module.exports = factory;
    }
    else if (typeof define === "function")  // AMD/CMD/Sea.js
    {
        if (define.amd) // for Require.js
        {
            /* Require.js define replace */
        } 
        else 
        {
            define(["jquery"], factory);  // for Sea.js
        }
    } 
    else
    { 
        window.editormd = factory();
    }
    
}(function() {    

    /* Require.js assignment replace */
    
    "use strict";
    
    var $ = (typeof (jQuery) !== "undefined") ? jQuery : Zepto;

    if (typeof ($) === "undefined") {
        return ;
    }

I don't understand what factory is or what it's doing.

The error is:

Uncaught TypeError: editormd.markdownToHTML is not a function
    at HTMLDocument.<anonymous> (my-file.js:15:1)
    at mightThrow (jquery.js:3762:1)
    at process (jquery.js:3830:1)

So my question is, am I able to import editormd as a variable into my script? I am using Webpack 5 and trying to include editormd in one of my entry point scripts.

Jarad
  • 17,409
  • 19
  • 95
  • 154

0 Answers0