4

Does anyone know if there's a way to auto format ColdFusion documents on VSCode the way it does for HTML files?

1
  • For those who are looking for the same formatting solution. I found that the easiest way is to install Unibeautify extension on VSC Commented Mar 6, 2019 at 16:52

2 Answers 2

5

Auto format HTML, JS & CSS within CFM/CFML files?

If you want, you can install the Beautify and then add cfc, cfm, & cfml as languages in the settings.json file. After that, you can use "Beautify Selection" or "Beautify File" to modify code. If the plugin can't decide what type of code you are formatting, it will prompt you for "HTML, JS or CSS". (I've assigned a shortcut so I don't have to press CTRL+SHIFT+P to search for the the beautify option.)

SETTINGS.JSON

"beautify.config" : {
    "beautify.language": {
        "js": ["js","json","cfc"],
        "css": ["css", "scss"],
        "html": ["htm", "html", "cfml", "cfm"]
    },
    "html": {
        "allowed_file_extensions": ["htm", "html", "xhtml", "shtml", "xml", "svg", "cfm", "cfml"]
    }
}
Sign up to request clarification or add additional context in comments.

8 Comments

Hey James, this does work but some tags are off by doing this.
"some tags"? I'll need more details in order to provide a response.
For example, multiple <cfset /> tags would be indented on each line even though they are self closing tags. Hope this makes more sense
ok... some "CFTags". I'm not sure how that would work. (When using UltraEdit, they always generated secondary auto-closing tags and there was no way to identify which tags to not do it to... it was all or nothing, so we chose nothing.) I beleive that standard "HTML" formatting rules are all that can be applied. I don't know how you are applying line breaks or the context of the code... so results may vary. The initial problem I encountered was that I couldn't format portions of HTML, CS & JS within a CFM template, I didn't attempt to reformat CFML.
Sharing for other readers: I found that for Beautify's settings.json, it's not "cfc" and "cfm" that should be added (being the file extensions one may use) for the "beautify.language" options like "html", but instead "cfml", as that's the vscode "language mode" which gets selected (by other settings for those extensions). This especially would trip someone up who saw James' example above and left off "cfml" because they "don't use that extension".
|
1

In VS Code, click on Extensions on the left side. Or View >> Extensions (or CTRL-SHIFT-X on Windows). Enter "CFML" in the Search box, and choose KamasamaK's extension (kamasamak.vscode-cfml). It is an excellent extension. There are also others, if you're interested.

Or https://marketplace.visualstudio.com/items?itemName=KamasamaK.vscode-cfml

2 Comments

That still doesn't support format for HTML within <cfoutput> though, right? I think that's what OP was asking for.
Yup, I already have that extension for syntax. It doesn't have auto format features.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.