npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@domternal/extension-code-block-lowlight

v1.3.1

Published

Code block with syntax highlighting via lowlight for Domternal editor

Readme

@domternal/extension-code-block-lowlight

Version MIT License

Syntax-highlighted code blocks for the Domternal editor, powered by lowlight. CodeBlockLowlight adds language detection and Tab indentation to the core CodeBlock, while retaining its commands, input rules, and toolbar actions. The package also includes HTML export helpers.

Documentation · Live examples

Install

The package declares Node.js 22 or later for tooling.

pnpm add @domternal/core @domternal/pm @domternal/extension-code-block-lowlight lowlight@^3 @domternal/theme

Requires @domternal/core and @domternal/pm >=1.3.0 <2.0.0, plus lowlight ^3.0.0. Use version 1.3.1 for all installed Domternal packages. Supply a configured lowlight instance as shown below. The theme supplies syntax colors; you can use your own highlight.js-compatible stylesheet instead.

Quick start

Add a host, then run the TypeScript after it is mounted in a browser app that supports CSS imports:

<div class="dm-editor"><div id="editor"></div></div>
import { Editor, StarterKit } from '@domternal/core';
import { CodeBlockLowlight } from '@domternal/extension-code-block-lowlight';
import { createLowlight, common } from 'lowlight';
import '@domternal/theme';

const lowlight = createLowlight(common);
const extensions = [
  StarterKit.configure({ codeBlock: false }),
  CodeBlockLowlight.configure({ lowlight }),
];

const editor = new Editor({
  element: document.getElementById('editor')!,
  extensions,
  content: '<pre><code class="language-javascript">const answer = 42;</code></pre>',
});

Disable StarterKit's codeBlock as shown: both extensions use the codeBlock node name and must not be registered together. Call editor.destroy() when removing the editor.

Commands and languages

import type { CodeBlockLowlightStorage } from '@domternal/extension-code-block-lowlight';

editor.chain().focus().toggleCodeBlock({ language: 'typescript' }).run();
editor.commands.setCodeBlock({ language: 'javascript' });

const codeBlocks = editor.storage.codeBlock as CodeBlockLowlightStorage;
const languages = codeBlocks.listLanguages();

Storage uses codeBlock, not codeBlockLowlight. The default common language set is a useful starting point. For a smaller bundle, call createLowlight() without a set and register only the languages you need with lowlight.register(name, syntax).

Common options

| Option | Default | Use | | --- | --- | --- | | lowlight | null | Required configured lowlight instance. Without it, highlighting is skipped and an editor error is reported. | | defaultLanguage | null | Language to use when the block has no language. | | autoDetect | true | Detect a language when no registered explicit or default language applies. | | tabIndentation | true | Tab inserts spaces and Shift-Tab removes leading spaces in code blocks. | | tabSize | 2 | Spaces per indentation step. |

Core CodeBlock options such as languageClassPrefix, exitOnTripleEnter, and HTMLAttributes remain available. Highlighting emits hljs-* token classes; @domternal/theme colors them using overridable --dm-syntax-* variables.

Export highlighted HTML

Editor decorations are not part of editor.getHTML(). For highlighted output, use one of these paths with the editor, extensions, and lowlight from the example:

import { inlineStyles } from '@domternal/core';
import {
  generateHighlightedHTML,
  createCodeHighlighter,
} from '@domternal/extension-code-block-lowlight';

// HTML with syntax token classes for a page that loads syntax CSS.
const html = generateHighlightedHTML(editor.getJSON(), extensions, lowlight);

// HTML with inline styles for an email or another destination without the theme.
const styledHtml = inlineStyles(editor.getHTML(), {
  codeHighlighter: createCodeHighlighter(lowlight),
});

Both helpers accept { defaultLanguage?, autoDetect? } as their final argument. Export auto-detection defaults to false; set it explicitly if you want detection outside the editor. generateHighlightedHTML also accepts document for a custom DOM implementation. Server rendering needs a DOM document, supplied explicitly or through the core's optional linkedom dependency. Use the same document schema for stored JSON. See the export reference for details.