developit / snarkdown

:smirk_cat: A snarky 1kb Markdown parser written in JavaScript
http://jsfiddle.net/developit/828w6t1x/
MIT License
2.28k stars 110 forks source link

Small update to the regex to allow for windows-y line endings #93

Closed ansballard closed 1 year ago

ansballard commented 3 years ago

I was working on a component that used snarkdown/marked on my mac, and it was working fine. Then I switched to my windows desktop to make some quick changes, and parsing code blocks was broken. I was pulling them via esbuild loaders, and feeding an inline string worked fine. I finally figured out that \r\n was being used instead of \n for the line endings, and I guess that breaks the regex.

So my possible fix is essentially just to prefix each \n with an optional \r. The bundle grows by about 6 bytes on average (not past 1k), comparison is below.

Workaround is just to replace carriage returns in the input before it's fed in, which is fine, but it'd be nice to offload that into the library if possible.

Thanks!

Before

Build "snarkdown" to dist:
  990 B: snarkdown.js.gz
  912 B: snarkdown.js.br
  986 B: snarkdown.modern.js.gz
  916 B: snarkdown.modern.js.br
  990 B: snarkdown.es.js.gz
  915 B: snarkdown.es.js.br
  1074 B: snarkdown.umd.js.gz
  978 B: snarkdown.umd.js.br

After

Build "snarkdown" to dist:
  996 B: snarkdown.js.gz (+6)
  919 B: snarkdown.js.br (+7)
  992 B: snarkdown.modern.js.gz (+6)
  922 B: snarkdown.modern.js.br (+6)
  996 B: snarkdown.es.js.gz (+6)
  915 B: snarkdown.es.js.br (+0) ??
  1081 B: snarkdown.umd.js.gz (+7)
  983 B: snarkdown.umd.js.br (+5)