No JavaScript for scripts?

Ask how to do things or if a certain feature is available in the program.
Post Reply
Andreas
Posts: 10
Joined: 05 May 2016 18:44
Location: DE Mönchengladbach

No JavaScript for scripts?

Post by Andreas »

Is it correct that I cannot use JavaScript for scripts?

I wanted to program 3 scripts or addons, namely HTML Beautifier, CSS Beautifier and JS Beautifier.

My script looks something like this, but it doesn't work.

Code: Select all

import "beautify-css.js" // comma separated for multiple

// var section
var
  css = "",
  beautifyOptions = {
    indent_size:                2,          // Indentation size [4]
    indent_char:                " ",        // Indentation character [" "]
    indent_with_tabs:           false,      // Indent with tabs, overrides -s and -c
    eol:                        "\n",       // Character(s) to use as line terminators. (default newline - "\\n")
    end_with_newline:           true,       // End output with newline
    brace_style:                "collapse", // [collapse|expand] ["collapse"]
    selector_separator_newline: true,       // Add a newline between multiple selectors
    newline_between_rules:      false,      // Add a newline between CSS rules
    indent_empty_lines:         false,      // Keep indentation on empty lines
    space_around_selector_separator: true
  }
;

// procedures and function
function p1() {
  css_beautify = require("js-beautify").css;

  css = Document.Text;
  css = css_beautify(css);

  Document.Text = css;
}

// Main procedure that will be executed when you run the script.
p1();
User avatar
pjj
Posts: 2109
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: No JavaScript for scripts?

Post by pjj »

Great question! (And great ideas, if I may say so.) Sadly, I don't know the answer; I guess only Rickard would know. I suppose, though, that it would not always be feasible (if at all). RJ TE uses quite old JavaScript engine provided by FastScript component, and debugging its scripts is... tough. Even if there is a way to import JS library, FS engine would probably choke on newer JS syntax (and debugging would be even tougher). I would be most happy to be proven wrong!

Having said that: there are other ways to accomplish to some extent what you want:
  • HTML > Offline validation uses Tidy to "beautify" HTML
  • use may use local programs to do the job (e.g. CssTidy)
  • you may use on-line services to run on your source files (e.g. I use JS minifier and CSS minifier this way, albeit not directly using "send POST request to URL" Tool item Type, but rather through a .bat file that calls .php script)
If I set to write such a script, I would rather process it through an executable (Node, PHP) run as RJ TE tool and (possibly) capture output in the editor.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
User avatar
Rickard Johansson
Site Admin
Posts: 6577
Joined: 19 Jul 2006 14:29

Re: No JavaScript for scripts?

Post by Rickard Johansson »

You may be able to add a script as a tool (using e.g. Node.js) and capture the output into a new document (see options when adding new tool to the tools menu).

The internal script engine is very simple and only use a JavaScript/Cpp/Pascal/VB like syntax.
User avatar
yereverluvinuncleber
Posts: 367
Joined: 20 Apr 2018 09:49

Re: No JavaScript for scripts?

Post by yereverluvinuncleber »

Instead of using node.js which is rather bulky and to my mind intimidating, you could use the old YWE widget engine which uses ECMA 4 and build a desktop application that does whatever you want using javascript. It is a little old, being ECMAScript 262 edition 3 but there are .js polyfills available for later functionality.

The same advice could be given with the Xwidget engine that uses MS JScript as provided with IE, each can create a desktop application with GUI. Extremely RAD and the important thing here to note is that you can create desktop apps with .js.

No-one ever quite cottoned onto the fact that you could build real desktop apps with .js using these engines. Always surprised me.
"Noli pati a scelestis opprimi"... or is it "non lacessit illegitimae te carborundum"?

You can find me on Deviantart https://www.deviantart.com/yereverluvinuncleber/gallery/
Post Reply