2021-10-14 06:13:50 +08:00
|
|
|
---
|
|
|
|
description: Developers love to add some inline code to their texts.
|
2021-10-15 03:20:21 +08:00
|
|
|
icon: code-view
|
2021-10-14 06:13:50 +08:00
|
|
|
---
|
|
|
|
|
2020-08-19 03:39:41 +08:00
|
|
|
# Code
|
2021-01-25 17:35:52 +08:00
|
|
|
[![Version](https://img.shields.io/npm/v/@tiptap/extension-code.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-code)
|
|
|
|
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-code.svg)](https://npmcharts.com/compare/@tiptap/extension-code?minimal=true)
|
|
|
|
|
2020-09-02 21:26:46 +08:00
|
|
|
The Code extensions enables you to use the `<code>` HTML tag in the editor. If you paste in text with `<code>` tags it will rendered accordingly.
|
2020-08-19 03:39:41 +08:00
|
|
|
|
2020-09-23 15:31:05 +08:00
|
|
|
Type something with <code>\`back-ticks around\`</code> and it will magically transform to `inline code` while you type.
|
2020-09-15 23:26:35 +08:00
|
|
|
|
2020-09-23 15:52:04 +08:00
|
|
|
## Installation
|
|
|
|
```bash
|
2020-10-30 21:24:16 +08:00
|
|
|
# with npm
|
2020-09-23 15:52:04 +08:00
|
|
|
npm install @tiptap/extension-code
|
|
|
|
|
2020-10-30 21:24:16 +08:00
|
|
|
# with Yarn
|
2020-09-23 15:52:04 +08:00
|
|
|
yarn add @tiptap/extension-code
|
|
|
|
```
|
|
|
|
|
2020-09-23 18:03:03 +08:00
|
|
|
## Settings
|
2021-10-02 05:27:39 +08:00
|
|
|
|
|
|
|
### HTMLAttributes
|
|
|
|
Custom HTML attributes that should be added to the rendered HTML tag.
|
|
|
|
|
|
|
|
```js
|
|
|
|
Code.configure({
|
|
|
|
HTMLAttributes: {
|
|
|
|
class: 'my-custom-class',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
```
|
2020-08-19 03:39:41 +08:00
|
|
|
|
2020-08-20 21:33:16 +08:00
|
|
|
## Commands
|
2021-10-02 05:25:07 +08:00
|
|
|
|
|
|
|
### setCode()
|
|
|
|
Mark text as inline code.
|
|
|
|
|
|
|
|
```js
|
|
|
|
editor.commands.setCode()
|
|
|
|
```
|
|
|
|
|
|
|
|
### toggleCode()
|
|
|
|
Toggle inline code mark.
|
|
|
|
|
|
|
|
```js
|
|
|
|
editor.commands.toggleCode()
|
|
|
|
```
|
|
|
|
|
|
|
|
### unsetCode()
|
|
|
|
Remove inline code mark.
|
|
|
|
|
|
|
|
```js
|
|
|
|
editor.commands.unsetCode()
|
|
|
|
```
|
2020-08-19 03:39:41 +08:00
|
|
|
|
2020-09-10 17:24:33 +08:00
|
|
|
## Keyboard shortcuts
|
2021-10-02 05:04:47 +08:00
|
|
|
| Command | Windows/Linux | macOS |
|
|
|
|
| ------------ | ------------------ | -------------- |
|
|
|
|
| toggleCode() | `Control` `E` | `Cmd` `E` |
|
2020-08-19 03:39:41 +08:00
|
|
|
|
2020-09-21 22:59:28 +08:00
|
|
|
## Source code
|
2021-04-21 21:31:11 +08:00
|
|
|
[packages/extension-code/](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-code/)
|
2020-08-19 03:39:41 +08:00
|
|
|
|
2020-09-02 21:26:46 +08:00
|
|
|
## Usage
|
2021-10-19 00:01:47 +08:00
|
|
|
https://embed.tiptap.dev/preview/Marks/Code
|