Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@tiptap/extension-code-block-lowlight
Advanced tools
@tiptap/extension-code-block-lowlight is an extension for the Tiptap editor that provides syntax highlighting for code blocks using the Lowlight library. It allows developers to easily integrate code block syntax highlighting into their Tiptap-based rich text editors.
Basic Code Block with Syntax Highlighting
This code sample demonstrates how to set up a Tiptap editor with the CodeBlockLowlight extension to enable syntax highlighting for JavaScript code blocks.
const { Editor } = require('@tiptap/core');
const CodeBlockLowlight = require('@tiptap/extension-code-block-lowlight');
const lowlight = require('lowlight');
const editor = new Editor({
extensions: [
CodeBlockLowlight.configure({ lowlight })
],
content: '<pre><code class="language-js">console.log("Hello, world!")</code></pre>'
});
Custom Language Support
This code sample shows how to register a custom language (XML in this case) with Lowlight and use it in the Tiptap editor for syntax highlighting.
const { Editor } = require('@tiptap/core');
const CodeBlockLowlight = require('@tiptap/extension-code-block-lowlight');
const lowlight = require('lowlight');
const xml = require('highlight.js/lib/languages/xml');
lowlight.registerLanguage('xml', xml);
const editor = new Editor({
extensions: [
CodeBlockLowlight.configure({ lowlight })
],
content: '<pre><code class="language-xml"><note><to>Tove</to></note></code></pre>'
});
Dynamic Language Switching
This code sample demonstrates how to dynamically change the language of a code block in the Tiptap editor using the CodeBlockLowlight extension.
const { Editor } = require('@tiptap/core');
const CodeBlockLowlight = require('@tiptap/extension-code-block-lowlight');
const lowlight = require('lowlight');
const editor = new Editor({
extensions: [
CodeBlockLowlight.configure({ lowlight })
],
content: '<pre><code class="language-js">console.log("Hello, world!")</code></pre>'
});
// Dynamically change the language of a code block
editor.commands.setCodeBlockLanguage('language-python');
Prism is a lightweight, extensible syntax highlighter. It is a popular choice for syntax highlighting in web applications and can be used with various editors. Unlike @tiptap/extension-code-block-lowlight, Prism is not specifically designed for Tiptap but can be integrated with it.
Highlight.js is a syntax highlighter written in JavaScript. It works in the browser as well as on the server. Similar to Lowlight, it supports a wide range of languages and is highly configurable. It can be used with Tiptap through custom extensions.
CodeMirror is a versatile text editor implemented in JavaScript for the browser. It is specialized for editing code and comes with built-in syntax highlighting. While it is a full-fledged code editor, it can be integrated with Tiptap for advanced code editing features.
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.
Documentation can be found on the Tiptap website.
Tiptap is open sourced software licensed under the MIT license.
FAQs
code block extension for tiptap
We found that @tiptap/extension-code-block-lowlight demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.