Posts

Showing posts with the label javascript

Browser in Javascript

Image
  A Proof-of-Concept Browser written in Javascript for minimal Web 2.0 browsing experience. This DOES NOT depend on any browser engine like Blink, Gecko or Webkit. Use an existing HTML rendering engine like netsurf or roll-out your own . This uses QuickJS-ng for JS runtime, Linkedom for DOM API and curl for network downloads. Font decoration uses Terminal ANSI escape codes . Since linkedom is an npm module, it needs to be converted to ES6 module for use with quickjs.  sudo apt install npm  npm install linkedom npx esbuild node_modules/linkedom/esm/index.js \     --bundle \     --format=esm \     --outfile= linkedom.bundle.js \     --platform=neutral \     -- main-fields = module,main           Code https://gitlab.com/atamariya/quickjs/-/blob/dev/ldom.js https://gitlab.com/atamariya/quickjs/-/blob/dev/net.js https://gitlab.com/atamariya/quickjs/-/blob/dev/render.js   Lessons Learnt st...

Semantic lexer based indent region function in Emacs

Image
  Here is a Semantic lexer based indent region function for formatting code in Emacs. It should work for Java and javascript. Feel free to use it if you like the output or customize it to suit your needs. Code: semantic-indent-region  Features Removes redundant whitespace. Multiple new lines are replaced by two new lines to mark paragraph separation. Adds spaces around punctuation characters. Uses tab for indent and fill-column width to wrap lines. Set values for tab-width and fill-column as per your preference. Uses first token as the anchor point and aligns the code to match the nearest tab-stop. e.g. if tab-width is 4 character, and first token is on 1-3 column, code will be aligned to first column. However, if first token is on 4th column, then alignment is not changed. Adds one indent for each level of nested code. Splits line on semi-colon.