Reformat Code formats .isml files from their ISML and HTML tag structure. Indentation mode (default) only sets each line's indentation. Full mode also tidies inside the lines. Formatting is free and works while the IDE indexes
Cmd+Alt+L) in the default Indentation mode changes only the indentation. <iselse> lines up with its <isif>, and the text of every line stays as you wrote itFormat a template
- Code › Reformat Code (
Cmd+Alt+L,Ctrl+Alt+L) formats the file, or the selected lines at the depth the whole template gives them - Code › Reformat File... (
Cmd+Alt+Shift+L,Ctrl+Alt+Shift+L) asks for the scope first. Reformat Code on a Project view folder formats every template in it - To format on save, turn on Reformat code in Settings › Tools › Actions on Save and pick ISML
Indentation mode keeps the line count, Full mode may wrap long start tags. Formatting twice changes nothing
Indentation mode
- Tags with a body, such as
<isif>,<isloop>,<isdecorate>and<isobject>, indent their content one level <iselseif>and<iselse>line up with their<isif>, with the lines after them one level in- HTML start and end tags pair as written, so a table whose rows come from an
<isloop>in a cell indents correctly. Where ISML and HTML cross, the ISML tags set the depth <isscript>,<script>and<style>bodies move as a whole, keeping their relative indentation- Multi-line start tags,
${...}and comments move with their first line. The<iscomment>body moves as a whole too, where the VS Code formatter indents it <pre>,<textarea>and multi-line JavaScript strings and template literals never move
Nothing is rewritten, joined or split, apart from the bare # escapes. Indentation follows Settings › Editor › Code Style › ISML › Tabs and Indents, or indent_size and indent_style in .editorconfig
Full mode
Full mode also:
- Leaves one space between attributes and none around
=. ISML tags keep a space before/>when they had one - Removes the spaces inside
${ }, or puts one on each side with Expression braces ${ } - Wraps and aligns ISML tag attributes per the ISML attributes options. HTML tags follow Settings › Editor › Code Style › HTML
- Formats
<isscript>,<script>and<style>bodies with the JavaScript and CSS formatters. A<script>containing${...}keeps its lines - Keeps blank lines up to Keep blank lines of the HTML code style and removes trailing spaces
<iscomment>, HTML comments and <pre> keep their text. Code inside ${...} keeps its spacing unless Format ${} expressions with the JavaScript formatter is on:
<isprint value = "${ Resource.msg('x','y',null) }" encoding="off" />
<p>${a+b}</p>Attribute wrapping
With ISML attributes (full mode) set to Wrap always, each attribute after the first goes on its own line:
<isinclude template="components/header"
sf-toolkit="off" />Wrap if long wraps only start tags past Hard wrap at. With Keep line breaks off, a split ISML start tag is joined back into one line
Bare # in template text
In both modes, Reformat Code writes each bare # of the template text as ${'#'}, or ${"#"} inside single quotes, the fix of the Unescaped # error. Code › Optimize Imports (Ctrl+Alt+O) writes the same escapes without formatting. A selection gets escapes only inside it
<a href="#reviews" style='color: #1a73e8'>Reviews</a>
<isprint value="${product.price}" formatter="#,##0.00" />becomes
<a href="${'#'}reviews" style='color: ${"#"}1a73e8'>Reviews</a>
<isprint value="${product.price}" formatter="#,##0.00" />formatter is an ISML attribute, so its # stays. To keep bare #, turn off Escape bare # as ${'#'}
Code style options
In Settings › Editor › Code Style › ISML. Options marked full mode do nothing in Indentation mode
| Tab | Option | Default |
|---|---|---|
| ISML | Formatter mode: Indentation or Full | Indentation |
| ISML | Format ${} expressions with the JavaScript formatter (full mode) | Off |
| ISML | Escape bare # as ${'#'} (Reformat Code and Optimize Imports) | On |
| Tabs and Indents | Indent ISML tag bodies | On |
| Tabs and Indents | Indent <isscript> body | On |
| Tabs and Indents | Align <iselse> and <iselseif> with <isif>. Off indents the branches like body lines | On |
| Tabs and Indents | Do not indent children of: HTML element names, separated by commas | Empty |
| Spaces | Expression braces ${ } (full mode) | Off |
| Wrapping and Braces | Hard wrap at and Wrap on typing | The IDE defaults |
| Wrapping and Braces | ISML attributes (full mode): Do not wrap, Wrap if long, Chop down if long or Wrap always | Do not wrap |
| Wrapping and Braces | Align when multiline | Off |
| Wrapping and Braces | Keep line breaks | On |
| Wrapping and Braces | New line after the tag name when multiline | Off |
| Wrapping and Braces | New line before > when multiline | Off |
The HTML code style's own Do not indent children of list doesn't apply to templates
EditorConfig
Share the options through .editorconfig with ij_isml_ keys:
[*.isml]
indent_size = 4
ij_isml_formatter_mode = full
ij_isml_attribute_wrap = on_every_item
ij_isml_align_attributes = true
ij_isml_spaces_within_expression_braces = false
ij_isml_format_expressions = true| Key | Values |
|---|---|
ij_isml_formatter_mode | indentation, full |
ij_isml_attribute_wrap | off, normal (wrap if long), on_every_item (chop down if long), split_into_lines (wrap always) |
ij_isml_align_attributes, ij_isml_keep_line_breaks_in_tags, ij_isml_new_line_after_tag_name, ij_isml_new_line_before_tag_end | true, false |
ij_isml_indent_tag_bodies, ij_isml_indent_script_body, ij_isml_align_branches_with_isif | true, false |
ij_isml_spaces_within_expression_braces, ij_isml_format_expressions, ij_isml_escape_bare_hash | true, false |
ij_isml_do_not_indent_children_of | HTML element names, separated by commas |
Export › EditorConfig File on the code style page writes every option
Matching the VS Code formatter
Indentation mode follows the VS Code Indentation formatter, apart from the <iscomment> body. For VS Code intellij-sfcc.isml.formatter.wrapAttributes values, use Full mode with these settings, under ISML attributes for ISML tags and in the HTML code style for HTML tags:
| VS Code value | JetBrains settings |
|---|---|
preserve | Do not wrap |
preserve-aligned | Do not wrap with Align when multiline |
auto | Wrap if long |
aligned-multiple | Wrap if long with Align when multiline |
force | Wrap always |
force-aligned | Wrap always with Align when multiline |
force-expand-multiline | Wrap always with New line after the tag name and New line before > |