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 - npm Package Compare versions

Comparing version 6.4.5 to 6.4.6

8

CHANGELOG.md

@@ -0,1 +1,9 @@

## 6.4.6 (2023-08-28)
### Bug fixes
`autoCloseTags` now generates two separate transactions, so that the completion can be undone separately.
Add highlighting for the content of `<script>` tags with a type of `importmap` or `speculationrules`.
## 6.4.5 (2023-06-23)

@@ -2,0 +10,0 @@

4

dist/index.d.ts

@@ -46,3 +46,3 @@ import * as _codemirror_state from '@codemirror/state';

declare type NestedLang = {
type NestedLang = {
tag: string;

@@ -54,3 +54,3 @@ attrs?: (attrs: {

};
declare type NestedAttr = {
type NestedAttr = {
name: string;

@@ -57,0 +57,0 @@ tagName?: string;

import { parser, configureNesting } from '@lezer/html';
import { cssLanguage, css } from '@codemirror/lang-css';
import { typescriptLanguage, jsxLanguage, tsxLanguage, javascriptLanguage, javascript } from '@codemirror/lang-javascript';
import { javascriptLanguage, typescriptLanguage, jsxLanguage, tsxLanguage, javascript } from '@codemirror/lang-javascript';
import { EditorView } from '@codemirror/view';

@@ -501,2 +501,3 @@ import { EditorSelection } from '@codemirror/state';

const jsonParser = /*@__PURE__*/javascriptLanguage.parser.configure({ top: "SingleExpression" });
const defaultNesting = [

@@ -513,2 +514,5 @@ { tag: "script",

{ tag: "script",
attrs: attrs => attrs.type == "importmap" || attrs.type == "speculationrules",
parser: jsonParser },
{ tag: "script",
attrs(attrs) {

@@ -618,30 +622,32 @@ return !attrs.type || /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(attrs.type);

*/
const autoCloseTags = /*@__PURE__*/EditorView.inputHandler.of((view, from, to, text) => {
const autoCloseTags = /*@__PURE__*/EditorView.inputHandler.of((view, from, to, text, insertTransaction) => {
if (view.composing || view.state.readOnly || from != to || (text != ">" && text != "/") ||
!htmlLanguage.isActiveAt(view.state, from, -1))
return false;
let { state } = view;
let changes = state.changeByRange(range => {
let base = insertTransaction(), { state } = base;
let closeTags = state.changeByRange(range => {
var _a, _b, _c;
let { head } = range, around = syntaxTree(state).resolveInner(head, -1), name;
let didType = state.doc.sliceString(range.from - 1, range.to) == text;
let { head } = range, around = syntaxTree(state).resolveInner(head - 1, -1), name;
if (around.name == "TagName" || around.name == "StartTag")
around = around.parent;
if (text == ">" && around.name == "OpenTag") {
if (didType && text == ">" && around.name == "OpenTag") {
if (((_b = (_a = around.parent) === null || _a === void 0 ? void 0 : _a.lastChild) === null || _b === void 0 ? void 0 : _b.name) != "CloseTag" &&
(name = elementName(state.doc, around.parent, head)) &&
!selfClosers.has(name)) {
let hasRightBracket = view.state.doc.sliceString(head, head + 1) === ">";
let insert = `${hasRightBracket ? "" : ">"}</${name}>`;
return { range: EditorSelection.cursor(head + 1), changes: { from: head + (hasRightBracket ? 1 : 0), insert } };
let to = head + (state.doc.sliceString(head, head + 1) === ">" ? 1 : 0);
let insert = `</${name}>`;
return { range, changes: { from: head, to, insert } };
}
}
else if (text == "/" && around.name == "OpenTag") {
let empty = around.parent, base = empty === null || empty === void 0 ? void 0 : empty.parent;
if (empty.from == head - 1 && ((_c = base.lastChild) === null || _c === void 0 ? void 0 : _c.name) != "CloseTag" &&
(name = elementName(state.doc, base, head)) &&
!selfClosers.has(name)) {
let hasRightBracket = view.state.doc.sliceString(head, head + 1) === ">";
let insert = `/${name}${hasRightBracket ? "" : ">"}`;
let pos = head + insert.length + (hasRightBracket ? 1 : 0);
return { range: EditorSelection.cursor(pos), changes: { from: head, insert } };
else if (didType && text == "/" && around.name == "IncompleteCloseTag") {
let base = around.parent;
if (around.from == head - 2 && ((_c = base.lastChild) === null || _c === void 0 ? void 0 : _c.name) != "CloseTag" &&
(name = elementName(state.doc, base, head)) && !selfClosers.has(name)) {
let to = head + (state.doc.sliceString(head, head + 1) === ">" ? 1 : 0);
let insert = `${name}>`;
return {
range: EditorSelection.cursor(head + insert.length, -1),
changes: { from: head, to, insert }
};
}

@@ -651,5 +657,11 @@ }

});
if (changes.changes.empty)
if (closeTags.changes.empty)
return false;
view.dispatch(changes, { userEvent: "input.type", scrollIntoView: true });
view.dispatch([
base,
state.update(closeTags, {
userEvent: "input.complete",
scrollIntoView: true
})
]);
return true;

@@ -656,0 +668,0 @@ });

{
"name": "@codemirror/lang-html",
"version": "6.4.5",
"version": "6.4.6",
"description": "HTML language support for the CodeMirror code editor",

@@ -34,6 +34,6 @@ "scripts": {

"@codemirror/state": "^6.0.0",
"@codemirror/view": "^6.17.0",
"@lezer/html": "^1.3.0",
"@lezer/common": "^1.0.0",
"@lezer/css": "^1.1.0",
"@codemirror/view": "^6.2.2"
"@lezer/css": "^1.1.0"
},

@@ -40,0 +40,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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