Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.