2026-06-14 09:16:15 +00:00
|
|
|
# Code Style Keys
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
Code Style Keys is an Obsidian plugin that makes wrapping selected text in backticks faster while editing notes.
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
When you press the backtick key with text selected:
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
- Single-line selection becomes inline code: `selected text`.
|
2026-06-14 09:26:12 +00:00
|
|
|
- Multi-line selection becomes a fenced code block
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
The plugin also prevents duplicate trailing backticks that can appear from the original keypress.
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
## Why this plugin
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
This plugin is useful if you frequently format code snippets and want one quick key action instead of manually typing wrappers.
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
## How it works
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
The plugin listens for the `beforeinput` event. If the typed character is a backtick and the active editor has a selection, it:
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
1. Cancels the default input.
|
|
|
|
|
2. Replaces the selection with inline or fenced code syntax.
|
|
|
|
|
3. Performs a short cleanup pass to remove one extra trailing backtick when necessary.
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
## Install for development
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
1. Make sure Node.js 18+ is installed.
|
|
|
|
|
2. Install dependencies:
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
```bash
|
|
|
|
|
npm install
|
|
|
|
|
```
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
3. Start watch build:
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
```bash
|
|
|
|
|
npm run dev
|
|
|
|
|
```
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
4. In Obsidian, reload the app and enable Code Style Keys in Community Plugins.
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
## Build for production
|
2026-04-24 14:22:08 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
```bash
|
|
|
|
|
npm run build
|
|
|
|
|
```
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
## Manual installation
|
2022-12-05 20:49:16 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
Copy these files into your vault at:
|
2022-12-05 20:49:16 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
`<Vault>/.obsidian/plugins/code-style-keys/`
|
2022-12-05 20:55:39 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
- `main.js`
|
|
|
|
|
- `manifest.json`
|
|
|
|
|
- `styles.css` (if used)
|
|
|
|
|
|
|
|
|
|
Then reload Obsidian and enable the plugin.
|
|
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
|
|
This version has no settings.
|
|
|
|
|
|
|
|
|
|
## Compatibility
|
|
|
|
|
|
|
|
|
|
- Desktop and mobile supported (`isDesktopOnly: false`).
|
|
|
|
|
- Minimum app version is defined in `manifest.json`.
|
|
|
|
|
|
|
|
|
|
## Development notes
|
2022-12-05 20:49:16 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
- Entry point: `src/main.ts`
|
|
|
|
|
- Build tool: esbuild
|
|
|
|
|
- Lint:
|
2022-12-05 20:49:16 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
```bash
|
|
|
|
|
npm run lint
|
2022-12-05 20:49:16 +00:00
|
|
|
```
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
## License
|
2022-04-15 18:13:31 +00:00
|
|
|
|
2026-06-14 09:16:15 +00:00
|
|
|
MIT
|