Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Not sure where to start..

First off, you might want to look at this response as to whether using regexes for parsing markdown to HTML is safe.response as to whether using regexes for parsing markdown to HTML is safe. You are of course not parsing HTML, but the sentiment is still valid in my mind.

Second off, there is this and this on github, these parsers are a few hundred lines. You are missing use cases in your 30 lines of code. That is fine for a hobby site, not for a production site.

If you have doubts, you can always run MD tests on your code and see for your self.

Other than that;

  • If you insist on using regexes, at the very least add a line of comment of what you are trying to achieve, ideally add a second line with an example

  • Modifying standard objects, enough said..

  • Single letter variables ( f = b.substr(0, 2); ) are very unfortunate

  • 0 lines of comment together with the previous comment make for terrible code

  • html() -> If you learn 1 thing today, it should be that mere mortals (like you and me) should not write escapers or parsers from scratch, instead we should figure out how smarter people did it and re-use their work. In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents.In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents. If you are running this server side as per your comment, then I would suggest you look up how Chromium does it. You did well and only forgot about { '\'', "'" },

  • Assignments in if statements are considered bad form:

      while (typeof(i = find.shift()) == 'string' && typeof(j = replace.shift()) == 'string') t = t.replaceAll(i || '', j || '');
    

    To turn this into good code, you will have to roll this out to something like

      while ( find.length ){
        caterpillar = find.shift();
        butterfly = replace.shift();
        if( typeof caterpillar != 'string' || typeof butterfly != 'string' )
          break;
        //Turn all caterpillars into butterflies
        this = this.replaceAll( caterpillar , butterfly );
      }
    

All in all, you are re-inventing the wheel. If you want to continue with this code then you have your work cut out..

Not sure where to start..

First off, you might want to look at this response as to whether using regexes for parsing markdown to HTML is safe. You are of course not parsing HTML, but the sentiment is still valid in my mind.

Second off, there is this and this on github, these parsers are a few hundred lines. You are missing use cases in your 30 lines of code. That is fine for a hobby site, not for a production site.

If you have doubts, you can always run MD tests on your code and see for your self.

Other than that;

  • If you insist on using regexes, at the very least add a line of comment of what you are trying to achieve, ideally add a second line with an example

  • Modifying standard objects, enough said..

  • Single letter variables ( f = b.substr(0, 2); ) are very unfortunate

  • 0 lines of comment together with the previous comment make for terrible code

  • html() -> If you learn 1 thing today, it should be that mere mortals (like you and me) should not write escapers or parsers from scratch, instead we should figure out how smarter people did it and re-use their work. In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents. If you are running this server side as per your comment, then I would suggest you look up how Chromium does it. You did well and only forgot about { '\'', "'" },

  • Assignments in if statements are considered bad form:

      while (typeof(i = find.shift()) == 'string' && typeof(j = replace.shift()) == 'string') t = t.replaceAll(i || '', j || '');
    

    To turn this into good code, you will have to roll this out to something like

      while ( find.length ){
        caterpillar = find.shift();
        butterfly = replace.shift();
        if( typeof caterpillar != 'string' || typeof butterfly != 'string' )
          break;
        //Turn all caterpillars into butterflies
        this = this.replaceAll( caterpillar , butterfly );
      }
    

All in all, you are re-inventing the wheel. If you want to continue with this code then you have your work cut out..

Not sure where to start..

First off, you might want to look at this response as to whether using regexes for parsing markdown to HTML is safe. You are of course not parsing HTML, but the sentiment is still valid in my mind.

Second off, there is this and this on github, these parsers are a few hundred lines. You are missing use cases in your 30 lines of code. That is fine for a hobby site, not for a production site.

If you have doubts, you can always run MD tests on your code and see for your self.

Other than that;

  • If you insist on using regexes, at the very least add a line of comment of what you are trying to achieve, ideally add a second line with an example

  • Modifying standard objects, enough said..

  • Single letter variables ( f = b.substr(0, 2); ) are very unfortunate

  • 0 lines of comment together with the previous comment make for terrible code

  • html() -> If you learn 1 thing today, it should be that mere mortals (like you and me) should not write escapers or parsers from scratch, instead we should figure out how smarter people did it and re-use their work. In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents. If you are running this server side as per your comment, then I would suggest you look up how Chromium does it. You did well and only forgot about { '\'', "'" },

  • Assignments in if statements are considered bad form:

      while (typeof(i = find.shift()) == 'string' && typeof(j = replace.shift()) == 'string') t = t.replaceAll(i || '', j || '');
    

    To turn this into good code, you will have to roll this out to something like

      while ( find.length ){
        caterpillar = find.shift();
        butterfly = replace.shift();
        if( typeof caterpillar != 'string' || typeof butterfly != 'string' )
          break;
        //Turn all caterpillars into butterflies
        this = this.replaceAll( caterpillar , butterfly );
      }
    

All in all, you are re-inventing the wheel. If you want to continue with this code then you have your work cut out..

deleted 100 characters in body
Source Link
konijn
  • 33.8k
  • 5
  • 69
  • 264

Not sure where to start..

First off, you might want to look at this response as to whether using regexes for parsing markdown to HTML is safe. That answer is completely escaping the markdown regex parsingYou are of stackexchange which I consider quite solidcourse not parsing HTML, but the sentiment is still valid in my mind.

Second off, there is this and this on github, these parsers are a few hundred lines. You are missing use cases in your 30 lines of code. That is fine for a hobby site, not for a production site.

If you have doubts, you can always run MD tests on your code and see for your self.

Other than that;

  • If you insist on using regexes, at the very least add a line of comment of what you are trying to achieve, ideally add a second line with an example

  • Modifying standard objects, enough said..

  • Single letter variables ( f = b.substr(0, 2); ) are very unfortunate

  • 0 lines of comment together with the previous comment make for terrible code

  • html() -> If you learn 1 thing today, it should be that mere mortals (like you and me) should not write escapers or parsers from scratch, instead we should figure out how smarter people did it and re-use their work. In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents. If you are running this server side as per your comment, then I would suggest you look up how Chromium does it. You did well and only forgot about { '\'', "'" },

  • Assignments in if statements are considered bad form:

      while (typeof(i = find.shift()) == 'string' && typeof(j = replace.shift()) == 'string') t = t.replaceAll(i || '', j || '');
    

    To turn this into good code, you will have to roll this out to something like

      while ( find.length ){
        caterpillar = find.shift();
        butterfly = replace.shift();
        if( typeof caterpillar != 'string' || typeof butterfly != 'string' )
          break;
        //Turn all caterpillars into butterflies
        this = this.replaceAll( caterpillar , butterfly );
      }
    

All in all, you are re-inventing the wheel. If you want to continue with this code then you have your work cut out..

Not sure where to start..

First off, you might want to look at this response as to whether using regexes for parsing markdown is safe. That answer is completely escaping the markdown regex parsing of stackexchange which I consider quite solid.

Second off, there is this and this on github, these parsers are a few hundred lines. You are missing use cases in your 30 lines of code. That is fine for a hobby site, not for a production site.

If you have doubts, you can always run MD tests on your code and see for your self.

Other than that;

  • If you insist on using regexes, at the very least add a line of comment of what you are trying to achieve, ideally add a second line with an example

  • Modifying standard objects, enough said..

  • Single letter variables ( f = b.substr(0, 2); ) are very unfortunate

  • 0 lines of comment together with the previous comment make for terrible code

  • html() -> If you learn 1 thing today, it should be that mere mortals (like you and me) should not write escapers or parsers from scratch, instead we should figure out how smarter people did it and re-use their work. In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents. If you are running this server side as per your comment, then I would suggest you look up how Chromium does it. You did well and only forgot about { '\'', "'" },

  • Assignments in if statements are considered bad form:

      while (typeof(i = find.shift()) == 'string' && typeof(j = replace.shift()) == 'string') t = t.replaceAll(i || '', j || '');
    

    To turn this into good code, you will have to roll this out to something like

      while ( find.length ){
        caterpillar = find.shift();
        butterfly = replace.shift();
        if( typeof caterpillar != 'string' || typeof butterfly != 'string' )
          break;
        //Turn all caterpillars into butterflies
        this = this.replaceAll( caterpillar , butterfly );
      }
    

All in all, you are re-inventing the wheel. If you want to continue with this code then you have your work cut out..

Not sure where to start..

First off, you might want to look at this response as to whether using regexes for parsing markdown to HTML is safe. You are of course not parsing HTML, but the sentiment is still valid in my mind.

Second off, there is this and this on github, these parsers are a few hundred lines. You are missing use cases in your 30 lines of code. That is fine for a hobby site, not for a production site.

If you have doubts, you can always run MD tests on your code and see for your self.

Other than that;

  • If you insist on using regexes, at the very least add a line of comment of what you are trying to achieve, ideally add a second line with an example

  • Modifying standard objects, enough said..

  • Single letter variables ( f = b.substr(0, 2); ) are very unfortunate

  • 0 lines of comment together with the previous comment make for terrible code

  • html() -> If you learn 1 thing today, it should be that mere mortals (like you and me) should not write escapers or parsers from scratch, instead we should figure out how smarter people did it and re-use their work. In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents. If you are running this server side as per your comment, then I would suggest you look up how Chromium does it. You did well and only forgot about { '\'', "'" },

  • Assignments in if statements are considered bad form:

      while (typeof(i = find.shift()) == 'string' && typeof(j = replace.shift()) == 'string') t = t.replaceAll(i || '', j || '');
    

    To turn this into good code, you will have to roll this out to something like

      while ( find.length ){
        caterpillar = find.shift();
        butterfly = replace.shift();
        if( typeof caterpillar != 'string' || typeof butterfly != 'string' )
          break;
        //Turn all caterpillars into butterflies
        this = this.replaceAll( caterpillar , butterfly );
      }
    

All in all, you are re-inventing the wheel. If you want to continue with this code then you have your work cut out..

added 493 characters in body
Source Link
konijn
  • 33.8k
  • 5
  • 69
  • 264

Not sure where to start..

First off, you might want to look at this response as to whether using regexes for parsing markdown is safe. That answer is completely escaping the markdown regex parsing of stackexchange which I consider quite solid.

Second off, there is this and this on github, these parsers are a few hundred lines. You are missing use cases in your 30 lines of code. That is fine for a hobby site, not for a production site.

If you have doubts, you can always run MD tests on your code and see for your self.

Other than that;

  • If you insist on using regexes, at the very least add a line of comment of what you are trying to achieve, ideally add a second line with an example

  • Modifying standard objects, enough said..

  • Single letter variables ( f = b.substr(0, 2); ) are very unfortunate

  • 0 lines of comment together with the previous comment make for terrible code

  • html() -> If you learn 1 thing today, it should be that mere mortals (like you and me) should not write escapers or parsers from scratch, instead we should figure out how smarter people did it and re-use their work. In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents. If you are running this server side as per your comment, then I would suggest you look up how Chromium does it. You did well and only forgot about { '\'', "'" },

  • Assignments in if statements are considered bad form:

      while (typeof(i = find.shift()) == 'string' && typeof(j = replace.shift()) == 'string') t = t.replaceAll(i || '', j || '');
    

    To turn this into good code, you will have to roll this out to something like

      while ( find.length ){
        caterpillar = find.shift();
        butterfly = replace.shift();
        if( typeof caterpillar != 'string' || typeof butterfly != 'string' )
          break;
        //Turn all caterpillars into butterflies
        this = this.replaceAll( caterpillar , butterfly );
      }
    

All in all, you are re-inventing the wheel. If you want to continue with this code then you have your work cut out..

Not sure where to start..

First off, you might want to look at this response as to whether using regexes for parsing markdown is safe.

Second off, there is this and this on github, these parsers are a few hundred lines. You are missing use cases in your 30 lines of code. That is fine for a hobby site, not for a production site.

If you have doubts, you can always run MD tests on your code and see for your self.

Other than that;

  • If you insist on using regexes, at the very least add a line of comment of what you are trying to achieve, ideally add a second line with an example

  • Modifying standard objects, enough said..

  • Single letter variables ( f = b.substr(0, 2); ) are very unfortunate

  • 0 lines of comment together with the previous comment make for terrible code

  • html() -> If you learn 1 thing today, it should be that mere mortals (like you and me) should not write escapers or parsers from scratch, instead we should figure out how smarter people did it and re-use their work. In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents.

  • Assignments in if statements are considered bad form:

      while (typeof(i = find.shift()) == 'string' && typeof(j = replace.shift()) == 'string') t = t.replaceAll(i || '', j || '');
    

    To turn this into good code, you will have to roll this out to something like

      while ( find.length ){
        caterpillar = find.shift();
        butterfly = replace.shift();
        if( typeof caterpillar != 'string' || typeof butterfly != 'string' )
          break;
        //Turn all caterpillars into butterflies
        this = this.replaceAll( caterpillar , butterfly );
      }
    

All in all, you are re-inventing the wheel. If you want to continue with this code then you have your work cut out..

Not sure where to start..

First off, you might want to look at this response as to whether using regexes for parsing markdown is safe. That answer is completely escaping the markdown regex parsing of stackexchange which I consider quite solid.

Second off, there is this and this on github, these parsers are a few hundred lines. You are missing use cases in your 30 lines of code. That is fine for a hobby site, not for a production site.

If you have doubts, you can always run MD tests on your code and see for your self.

Other than that;

  • If you insist on using regexes, at the very least add a line of comment of what you are trying to achieve, ideally add a second line with an example

  • Modifying standard objects, enough said..

  • Single letter variables ( f = b.substr(0, 2); ) are very unfortunate

  • 0 lines of comment together with the previous comment make for terrible code

  • html() -> If you learn 1 thing today, it should be that mere mortals (like you and me) should not write escapers or parsers from scratch, instead we should figure out how smarter people did it and re-use their work. In jQuery, the authors call the DOM method .createTextNode(), which replaces special characters with their HTML entity equivalents. If you are running this server side as per your comment, then I would suggest you look up how Chromium does it. You did well and only forgot about { '\'', "'" },

  • Assignments in if statements are considered bad form:

      while (typeof(i = find.shift()) == 'string' && typeof(j = replace.shift()) == 'string') t = t.replaceAll(i || '', j || '');
    

    To turn this into good code, you will have to roll this out to something like

      while ( find.length ){
        caterpillar = find.shift();
        butterfly = replace.shift();
        if( typeof caterpillar != 'string' || typeof butterfly != 'string' )
          break;
        //Turn all caterpillars into butterflies
        this = this.replaceAll( caterpillar , butterfly );
      }
    

All in all, you are re-inventing the wheel. If you want to continue with this code then you have your work cut out..

Source Link
konijn
  • 33.8k
  • 5
  • 69
  • 264
Loading