jnk
This VSCode extension is a tool for generating JSX using concise Emmet-style syntax. It's like Emmet, but for React.
Usage
Method 1: Autocomplete (IntelliSense)
- Open a
.js , .ts , .jsx or .tsx file
- Type jnk syntax on a line (e.g.,
div.container>h1{Hello}+p{World} )
- Press
Cmd+Shift+J (Mac) or Ctrl+Shift+J (Windows/Linux) or trigger IntelliSense to show autocomplete
- Select "Compile with jnk" from the menu
- The entire line will be replaced with compiled JSX
Method 2: Keyboard Shortcut (Recommended)
- Open a
.jsx or .tsx file
- Type jnk syntax on a line (e.g.,
div.container>h1{Hello}+p{World} )
- Press
Cmd+Shift+J (Mac) or Ctrl+Shift+J (Windows/Linux)
- The entire line will be replaced with compiled JSX instantly
// Input jnk syntax:
div.container>h1{Hello}+p{World}
// Output JSX:
<div className="container">
<h1>Hello</h1>
<p>World</p>
</div>
// Input jnk syntax:
Button.primary[onClick={handleClick}]{Save}
// Output JSX:
<Button className="primary" onClick={handleClick}>Save</Button>
Supported jnk Syntax
div.class - Element with className
div#id - Element with id
div[prop=value] - Element with string props
div[prop={expression}] - Element with JS expression props
div{content} - Element with text content
div>{expression} - Element with JS expression content
div>child - Parent-child relationship
div+sibling - Sibling elements
div*3 - Multiply elements
div*{expression} - Expression multiplication (like map)
(div+p)*2 - Grouped elements
div$ - Numbering placeholder (div1, div2, etc.)
Features
- Smart Detection: Automatically detects jnk syntax patterns in JSX/TSX files
- Keyboard Shortcut:
Cmd+Shift+J (Mac) / Ctrl+Shift+J (Windows/Linux) for instant compilation
- Autocomplete Integration: Shows "Compile with jnk" option in IntelliSense menu
- Instant Compilation: Replaces jnk syntax with compiled JSX
- Error Handling: Shows helpful error messages if jnk compilation fails
Installation
For Development/Testing:
- Clone or download this extension
- Run
npm install to install dependencies
- Run
npm run compile to build the extension
- Press
F5 in VSCode to launch Extension Development Host
- Open a
.jsx or .tsx file in the new window to test
For Production Use:
- Install
vsce globally: npm install -g vsce
- Package the extension:
vsce package
- Install the generated
.vsix file in VSCode: code --install-extension jnk-autocomplete-0.0.1.vsix
Development
npm install
npm run compile
npm run watch # For continuous compilation during development
Requirements
- VSCode 1.74.0 or higher
- The
jnk npm package is bundled with the extension
Known Issues
- The extension currently replaces the entire line. Future versions may support inline compilation.
Contributing
Contributions are welcome. Please keep code clean and follow best practices.
License
MIT © Janko Stanic
| |