velocityjson
A Visual Studio Code extension for syntax highlighting of Velocity and JSON mixed code.
Features
This extension provides syntax highlighting for files that contain a mix of Velocity template language and JSON.
Key Features
- JSON Syntax Highlighting: Properly highlights JSON structures including objects, arrays, strings, numbers, booleans, and null values
- Velocity Syntax Highlighting: Highlights Velocity directives, variables, and comments
- Mixed Code Support: Seamlessly handles Velocity code within JSON structures
- Velocity variables inside JSON strings
- Velocity directives within JSON values
- Velocity code outside JSON structures
- Comprehensive Directive Support: Recognizes all common Velocity directives:
- Control structures:
#if, #else, #elseif, #end
- Loops:
#foreach
- Variable assignment:
#set
- Macros and includes:
#macro, #parse
- Flow control:
#break
Installation
From VS Code Marketplace
- Open VS Code
- Press
Ctrl+P (Windows/Linux) or Cmd+P (macOS)
- Type
ext install velocityjson and press Enter
- Click Install
From Source
- Clone or download this repository
- Open the folder in VS Code
- Press
F5 to run the extension in development mode
- Or package the extension using
vsce package and install the .vsix file
Usage
- Open a file containing Velocity and JSON mixed code
- Ensure the file is recognized as "Velocity+JSON" language mode:
- Click on the language mode indicator in the bottom right corner
- Select "Velocity+JSON" from the dropdown menu
- The extension will automatically apply syntax highlighting
Supported File Extensions
The extension is configured to work with the following file extensions:
.vm (Velocity files)
.json (JSON files)
You can also manually set the language mode to "Velocity+JSON" for any file.
Extension Settings
This extension contributes the following settings:
velocity.highlightLevel: Controls the intensity of syntax highlighting (default: "full")
basic: Basic syntax highlighting
full: Full syntax highlighting with all features
Example
Here's an example of how the extension highlights mixed Velocity and JSON code:
#set($count = 0)
#foreach($p in $param)
#if($p.sku)
#set($count = $count + 1)
#end
#end
{
"name": "Product",
"count": $count,
"items": [
#foreach($item in $items)
{
"id": "$item.id",
"name": "$item.name"
}#if($foreach.hasNext),#end
#end
]
}
Known Issues
Release Notes
0.0.1
Initial release of velocityjson extension with:
- Basic JSON syntax highlighting support
- Velocity directive and variable highlighting
- Mixed code support for Velocity within JSON structures
- Support for common Velocity directives
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Enjoy!