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

@codemirror/lang-html

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/lang-html

HTML language support for the CodeMirror code editor

  • 6.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
467K
increased by0.6%
Maintainers
2
Weekly downloads
 
Created

What is @codemirror/lang-html?

@codemirror/lang-html is a language support package for CodeMirror 6 that provides syntax highlighting, code folding, and other editing features for HTML. It is part of the CodeMirror 6 ecosystem, which is a versatile text editor implemented in JavaScript for the browser.

What are @codemirror/lang-html's main functionalities?

Syntax Highlighting

This code sets up a CodeMirror editor with HTML syntax highlighting. The `html` function from `@codemirror/lang-html` is used to provide the necessary language support.

import { html } from '@codemirror/lang-html';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';

const state = EditorState.create({
  doc: '<!DOCTYPE html>\n<html>\n  <head>\n    <title>My HTML</title>\n  </head>\n  <body>\n    <h1>Hello, world!</h1>\n  </body>\n</html>',
  extensions: [basicSetup, html()]
});

const view = new EditorView({
  state,
  parent: document.body
});

Code Folding

This code sets up a CodeMirror editor with HTML syntax highlighting and code folding. The `foldGutter` extension is used to add foldable regions to the editor.

import { html } from '@codemirror/lang-html';
import { foldGutter } from '@codemirror/fold';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';

const state = EditorState.create({
  doc: '<!DOCTYPE html>\n<html>\n  <head>\n    <title>My HTML</title>\n  </head>\n  <body>\n    <h1>Hello, world!</h1>\n  </body>\n</html>',
  extensions: [basicSetup, html(), foldGutter()]
});

const view = new EditorView({
  state,
  parent: document.body
});

Linting

This code sets up a CodeMirror editor with HTML syntax highlighting and linting. The `linter` and `lintGutter` extensions are used to add linting support to the editor.

import { html } from '@codemirror/lang-html';
import { linter, lintGutter } from '@codemirror/lint';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';

const state = EditorState.create({
  doc: '<!DOCTYPE html>\n<html>\n  <head>\n    <title>My HTML</title>\n  </head>\n  <body>\n    <h1>Hello, world!</h1>\n  </body>\n</html>',
  extensions: [basicSetup, html(), lintGutter(), linter((view) => [])]
});

const view = new EditorView({
  state,
  parent: document.body
});

Other packages similar to @codemirror/lang-html

Keywords

FAQs

Package last updated on 12 Jan 2023

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