showdown icon indicating copy to clipboard operation
showdown copied to clipboard

Broken with Browserify

Open leeola opened this issue 13 years ago • 17 comments

I attempted to use showdown with browserify and ran into a failure. The failure is due to Showdown trying to access the file system, based on the existence of require/etc.

My main question is.. why, why is it even doing this? If we look at the code in question..

//
// Automatic Extension Loading (node only):
//

if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof require !== 'undefind') {
    var fs = require('fs');

    if (fs) {
        // Search extensions folder
        var extensions = fs.readdirSync((__dirname || '.')+'/extensions').filter(function(file){
            return ~file.indexOf('.js');
        }).map(function(file){
            return file.replace(/\.js$/, '');
        });
        // Load extensions into Showdown namespace
        Showdown.forEach(extensions, function(ext){
            var name = stdExtName(ext);
            Showdown.extensions[name] = require('./extensions/' + ext);
        });
    }
}

Why is fs even being used here? This seems like a complex solution for something that a simple index.js file would handle just fine. On top of that, if an index.js file was used then Browserify would work out of the box.

leeola avatar Feb 20 '13 00:02 leeola

Would be nice to have it work w/ browserify, and there are other options aside from removing all server-side code. If there are truly differences between a browser build and what's used in node, you can provide a separate browser version via the browser property in package.json, which browserify respects. Sometimes it takes some organization in dependencies to make these separations clean.

https://gist.github.com/shtylman/4339901

selfcontained avatar Mar 26 '13 17:03 selfcontained

Well, in this case you wouldn't even need to provide two different versions. This version will work fine in both Browser and Server, it's just that the above code essentially recreates require for absolutely no reason (none that i can figure at least).

For now i'm just concating the js file, but eventually i need to fork this and fix the issue. I can't find a reason for the above filesystem calls :/

leeola avatar Mar 27 '13 15:03 leeola

+1

craigspaeth avatar Aug 01 '13 17:08 craigspaeth

This also bums me out, anybody have a fork out there already before I go make one?

ryanflorence avatar Aug 30 '13 02:08 ryanflorence

+1

ThomasDeutsch avatar Mar 20 '14 11:03 ThomasDeutsch

This causes it to fail with webmake as well. Wrapping the require in a try-catch would be sufficient as a quick fix. Not sure if that would help browserify or not.

SystemParadox avatar Apr 17 '14 14:04 SystemParadox

+1

erikras avatar Apr 17 '14 22:04 erikras

I don't think so, browserify uses static analysis, not runtime evaluation.

On Thu, Apr 17, 2014 at 4:42 PM, Erik Rasmussen [email protected]:

+1

— Reply to this email directly or view it on GitHubhttps://github.com/coreyti/showdown/issues/50#issuecomment-40771009 .

ryanflorence avatar Apr 18 '14 03:04 ryanflorence

+1

bhirt-bpl avatar May 21 '14 21:05 bhirt-bpl

Just use marked.

Showdown is clearly not maintained.

On May 21, 2014, at 3:19 PM, bhirt-bpl [email protected] wrote:

+1

— Reply to this email directly or view it on GitHub.

ryanflorence avatar May 22 '14 02:05 ryanflorence

Same problem with webpack.

gaearon avatar Jul 24 '14 01:07 gaearon

Any progress on this front? It's been a year and a half with no response.

mzabriskie avatar Sep 29 '14 03:09 mzabriskie

+1 for progress or an update on this...

pikeas avatar Oct 18 '14 07:10 pikeas

i have applied the @rjmackay pull requrest in my fork : https://github.com/aminroosta/aminroosta.github.io

no more browserify or webpack errors .

aminroosta avatar Dec 31 '14 17:12 aminroosta

I'm currently looking into this. Showdown will have a major rewriting as keeping up with the perl version doesn't make much sense now. Since we'll probably move each extension to its own repository, there will be no reason to call fs.

Regardless, the ideal way to approach the problem is abstracting the library from the platform it's running on, in a similar fashion to underscore.js method. This will make it compatible with node and browser out of the box and, consequently, compatible with browserify. It will also be easier to make the lib compatible with AMD and commonjs.

tivie avatar Jan 05 '15 00:01 tivie

It's fixed in the showdown2 branch. Note: You now need to instantiate converter using var converter = new Showdown.Converter();

zallek avatar Feb 15 '15 13:02 zallek

fixed in eae5f0e

tivie avatar May 15 '15 21:05 tivie