TotallyInformation/node-red-contrib-uibuilder

Relax the `fileType` function to permit Monaco (and ACE) to work with more file types

Steve-Mcl opened this issue · 2 comments

Software Version
Node.JS All
npm NA
Node-RED ALL
uibuilder node 3.0.0
OS All
Browser All

Hi Julian, as discussed here, is it possible you can relax the fileType function to permit Monaco (and ACE) to work with more file types?

The function that does the work is here:

/** Return a file type from a file name (or default to txt)
* ftype can be used in ACE editor modes */
function fileType(fname) {
var fparts = fname.split('.')
if (fparts.length > 1) {
var ftype = 'text'
var fext = fparts[1].toLowerCase().trim()
switch (fext) {
case 'js':
ftype = 'javascript'
break
case 'html':
case 'css':
case 'json':
ftype = fext
break
case 'vue':
ftype = 'html'
break
case 'md':
ftype = 'markdown'
break
case 'yaml':
case 'yml':
ftype = 'yaml'
break
default:
// txt
}
return ftype
} else {
return 'text'
}
} // --- End of fileType --- //

I will change the default entry to return the fext value rather than 'text'.

Assuming that doesn't create any issues, it will be incorporated into the next release.

Fixed.

Minor issue remains that you can "edit" binary files like images - I probably should stop that :-)

Also note that this change highlighted a couple of small bugs related to trying to edit dotfiles. Now also fixed. See #105 and #106