Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tiptap/extension-code-block-lowlight

Package Overview
Dependencies
Maintainers
5
Versions
193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tiptap/extension-code-block-lowlight

code block extension for tiptap

  • 2.5.0-pre.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
195K
increased by37.68%
Maintainers
5
Weekly downloads
 
Created

What is @tiptap/extension-code-block-lowlight?

@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.

What are @tiptap/extension-code-block-lowlight's main functionalities?

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');

Other packages similar to @tiptap/extension-code-block-lowlight

Keywords

FAQs

Package last updated on 03 Jul 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc