showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.26k stars 1.56k forks source link

Can not remove lang and output extension, using removeExtension method of converter #757

Open jhuix opened 4 years ago

jhuix commented 4 years ago

When you use removeExtension method of converter, you can not remove lang and output extension. Because removeExtension method has a bug. See below for details:

  this.removeExtension = function (extension) {
    if (!showdown.helper.isArray(extension)) {
      extension = [extension];
    }
    for (var a = 0; a < extension.length; ++a) {
      var ext = extension[a];
      for (var i = 0; i < langExtensions.length; ++i) {
        if (langExtensions[i] === ext) {
          // This is a bug,  langExtensions[i] is not a array.
          langExtensions[i].splice(i, 1);
        }
      }
      for (var ii = 0; ii < outputModifiers.length; ++i) {
        if (outputModifiers[ii] === ext) {
         // This is a bug,  outputModifiers[ii] is not a array 
         // and variable i is not an index of the outputModifiers array.
          outputModifiers[ii].splice(i, 1);
        }
      }
    }
  };
    this.converter.removeExtension = function(extension) {
        if (!showdown.helper.isArray(extension)) {
          extension = [extension];
        }
        const exts = this.getAllExtensions();
        let langExtensions = exts.language;
        let outputModifiers = exts.output;
        for (var a = 0; a < extension.length; ++a) {
          const ext = extension[a];
          for (var i = 0; i < langExtensions.length; ++i) {
            if (langExtensions[i] === ext) {
              // Fixed
              langExtensions.splice(i, 1);
            }
          }
          for (var j = 0; j < outputModifiers.length; ++j) {
            if (outputModifiers[j] === ext) {
              // Fixed
              outputModifiers.splice(j, 1);
            }
          }
        }
      };