wooorm / parse-entities

Parse HTML character references
MIT License
49 stars 12 forks source link

Use browser APIs instead of bundled character entity list in browsers #14

Closed rexxars closed 5 years ago

rexxars commented 5 years ago

I briefly discussed this with you (@wooorm) on Gitter - that the main bulk of remark-parse (in byte size) stems from this library including character-entities as a dependency.

You had a brilliant and simple solution in that one could actually just use innerHTML + textContent to decode entities in the browser.

This is a first stab at the problem. Tests seem to pass (do you have a preferred way of testing on CI in browsers?) both in node and browser, and the size decrease is already quite significant:

~/webdev/parse-entities [master] $ browserify index.js | bundle-collapser | uglifyjs -c -m | wc -c
    34797

~/webdev/parse-entities [master] $ git checkout slim-browser
Switched to branch 'slim-browser'

~/webdev/parse-entities [slim-browser] $ browserify index.js | bundle-collapser | uglifyjs -c -m | wc -c
    5282

Feel free to change any part of this you don't like - code style or implementation-wise, obviously.

rexxars commented 5 years ago

Variable declarations moved. Not sure about browser testing - perhaps we could try out tape-run? Uses electron, by default. Thoughts?

wooorm commented 5 years ago

Yeah sure let’s try that! Seems like tape-run, through browser-run, uses electron by default. It seems to accept other browsers, such as chrome, but then we need to install chrome it in Travis (apparently firefox is already on travis). I think I’d prefer a “pure” browser over electron, but I wouldn’t suggest spending too much time on it.

rexxars commented 5 years ago

Browser tests added. tape-run installs electron automatically, so I figured running the tests by default in electron (for developer ergonomics) and in both Electron and Firefox on Travis would be a good bet, so that's what I went for.

wooorm commented 5 years ago

Published, thanks @rexxars!

rexxars commented 5 years ago

Thanks a bunch <3