What is @tiptap/extension-code-block?
@tiptap/extension-code-block is an extension for the Tiptap editor that allows you to add and manage code blocks within your rich text editor. It provides functionality for syntax highlighting, code formatting, and more, making it easier to work with code snippets in a text editor.
What are @tiptap/extension-code-block's main functionalities?
Basic Code Block
This feature allows you to add a basic code block to your Tiptap editor. The code sample shows how to import and use the CodeBlock extension in a Tiptap editor instance.
import { CodeBlock } from '@tiptap/extension-code-block';
const editor = new Editor({
extensions: [
CodeBlock,
],
});
Syntax Highlighting
This feature enables syntax highlighting for code blocks. The code sample demonstrates how to configure the CodeBlock extension with the 'lowlight' library to provide syntax highlighting.
import { CodeBlock } from '@tiptap/extension-code-block';
import { lowlight } from 'lowlight';
const editor = new Editor({
extensions: [
CodeBlock.configure({
lowlight,
}),
],
});
Custom Language Support
This feature allows you to add support for custom languages in your code blocks. The code sample shows how to register a custom language (JavaScript in this case) with the 'lowlight' library and configure the CodeBlock extension to use it.
import { CodeBlock } from '@tiptap/extension-code-block';
import { lowlight } from 'lowlight';
import javascript from 'highlight.js/lib/languages/javascript';
lowlight.registerLanguage('javascript', javascript);
const editor = new Editor({
extensions: [
CodeBlock.configure({
lowlight,
}),
],
});
Other packages similar to @tiptap/extension-code-block
prismjs
Prism is a lightweight, extensible syntax highlighter. It is a standalone library that can be used to highlight code blocks in any web application. Compared to @tiptap/extension-code-block, Prism is more focused on syntax highlighting and does not provide rich text editing capabilities.
highlight.js
Highlight.js is a popular library for syntax highlighting. It automatically detects the language of the code block and applies the appropriate highlighting. While it is similar to the syntax highlighting feature of @tiptap/extension-code-block, Highlight.js is a standalone library and does not integrate with rich text editors like Tiptap.
codemirror
CodeMirror is a versatile text editor implemented in JavaScript for the browser. It is specialized for editing code and comes with a wide range of features including syntax highlighting, autocompletion, and more. Unlike @tiptap/extension-code-block, CodeMirror is a full-fledged code editor rather than an extension for a rich text editor.
@tiptap/extension-bode-block
Introduction
tiptap is a headless wrapper around ProseMirror – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as New York Times, The Guardian or Atlassian.
Offical Documentation
Documentation can be found on the tiptap website.
License
tiptap is open-sourced software licensed under the MIT license.