![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@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
The npm package @tiptap/extension-code-block-lowlight receives a total of 174,959 weekly downloads. As such, @tiptap/extension-code-block-lowlight popularity was classified as popular.
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 6 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.