A dead simple code editor with syntax highlighting and line numbers.
npm install vue-prism-editor[![Bundle size (minified + gzip)][bundle-size-badge]][bundle-size]
[![NPM Downloads][downloads-badge]][downloads]
[![Build Status][build-badge]][build]
![Codecov][covarage-badge]
[![Version][version-badge]][package]
[![MIT License][license-badge]][license]
> A dead simple code editor with syntax highlighting and line numbers. 3kb/z
Editor works both for Vue 2.x and Vue 3.x and you are currently on the branch that supports Vue 2.x.
Go here for the Vue 3.x compatible version
- Vue Example Codesandbox: https://codesandbox.io/s/61yrlnlnmn
- Nuxt Example Codesandbox: https://codesandbox.io/s/nuxt-vue-prism-editor-62e06
- Vite Example Codesandbox: https://codesandbox.io/s/vite-vue-prism-editor-q9j8p
- Codepen: https://codepen.io/koca/pen/QVgqyR
- Code Editing
- Modular syntax highlighting with third party library (not limited to prismjs)
- Indent line or selected text by pressing tab key, with customizable indentation
- Automatic indent on new lines
- Wrap selected text in parens, brackets, or quotes
- Undo / Redo whole words instead of letter by letter
- Accessible, use Ctrl+Shift+M (Mac) / Ctrl+M to toggle capturing tab key
- Works on mobile (thanks to textarea)
- Auto resize
- Line numbers
- Match line numbers styles to the theme(optional)
Several browser based code editors such as Ace, CodeMirror, Monaco etc. provide the ability to embed a full-featured code editor in your web page. However, if you just need a simple editor with syntax highlighting without any of the extra features, they can be overkill as they don't usually have a small bundle size footprint. This library aims to provide a simple code editor with syntax highlighting support without any of the extra features, perfect for simple embeds and forms where users can submit code.
``sh`
npm install vue-prism-editor
or
`sh`
yarn add vue-prism-editor
You need to use the editor with a third party library which provides syntax highlighting. For example, it'll look like following with prismjs:
Register the component locally and use it (recommended)
`html
`
> Note that depending on your syntax highlighter, you might have to include additional CSS for syntax highlighting to work.
Or register the component globally
`js`
import { PrismEditor } from 'vue-prism-editor';
import 'vue-prism-editor/dist/prismeditor.min.css'; // import the styles
Vue.component('PrismEditor', PrismEditor);
Browser usage (for codepen etc.):
`html
`
| Name | Type | Default | Options | Description |
| -------------------- | ------------------ | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| v-model value | string | "" | - | Current value of the editor i.e. the code to display |string => string
| highlight | | - | - | Callback which will receive text to highlight. You'll need to return an HTML string with syntax highlighting using a library such as prismjs. |Boolean
| readonly | | false | - | Readonly |Boolean
| lineNumbers | | false | - | Whether to show line numbers. Default false |Boolean
| autoStyleLineNumbers | | true | - | Match line numbers text color to the theme. Default true |number
| tabSize | | 2 | - | The number of characters to insert when pressing tab key. For example, for 4 space indentation, tabSize will be 4 and insertSpaces will be true. Default: 2 |boolean
| insertSpaces | | true | - | Whether to use spaces for indentation. Default: true. If you set it to false, you might also want to set tabSize to 1 |boolean
| ignoreTabKey | | false | - | Whether the editor should ignore tab key presses so that keyboard users can tab past the editor. Users can toggle this behaviour using Ctrl+Shift+M (Mac) / Ctrl+M manually when this is false. Default: false |
| Name | Parameters | Description |
| ------- | ---------- | ------------------------------------------------------------ |
| input | (code) | Fires when the code is changed. |(event)
| keydown | | This event is emitted when a keydown event happens in editor |(event)
| keyup | | This event is emitted when a keyup event happens in editor |(event)
| click | | This event is emitted when clicking anywhere in the editor |(event)
| focus | | This event is emitted when focus |(event)
| blur | | This event is emitted when blur |
_This part is taken from react-simple-code-editor_
It works by overlaying a syntax highlighted
block over a