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

@codemirror/highlight

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/highlight - npm Package Compare versions

Comparing version 0.18.4 to 0.19.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 0.19.0 (2021-08-11)
### Breaking changes
Update dependencies to 0.19.0
## 0.18.4 (2021-05-18)

@@ -2,0 +8,0 @@

10

dist/index.d.ts

@@ -1,3 +0,3 @@

import * as lezer_tree from 'lezer-tree';
import { NodeType, Tree } from 'lezer-tree';
import * as _lezer_common from '@lezer/common';
import { NodeType, Tree } from '@lezer/common';
import { StyleModule, StyleSpec } from 'style-mod';

@@ -51,3 +51,3 @@ import { Extension, EditorState } from '@codemirror/state';

via
[`Parser.configure`](https://lezer.codemirror.net/docs/ref#lezer.Parser.configure).
[`LRParser.configure`](https://lezer.codemirror.net/docs/ref#lr.LRParser.configure).

@@ -59,3 +59,3 @@ The argument object maps node selectors to [highlighting

Such a path can be a [node
name](https://lezer.codemirror.net/docs/ref#tree.NodeType.name),
name](https://lezer.codemirror.net/docs/ref#common.NodeType.name),
or multiple node names (or `*` wildcards) separated by slash

@@ -104,3 +104,3 @@ characters, as in `"Block/Declaration/VariableName"`. Such a path

[selector: string]: Tag | readonly Tag[];
}): lezer_tree.NodePropSource;
}): _lezer_common.NodePropSource;
/**

@@ -107,0 +107,0 @@ A highlight style associates CSS styles with higlighting

@@ -1,2 +0,2 @@

import { NodeProp, NodeType } from 'lezer-tree';
import { NodeProp, NodeType } from '@lezer/common';
import { StyleModule } from 'style-mod';

@@ -129,3 +129,3 @@ import { EditorView, ViewPlugin, Decoration } from '@codemirror/view';

via
[`Parser.configure`](https://lezer.codemirror.net/docs/ref#lezer.Parser.configure).
[`LRParser.configure`](https://lezer.codemirror.net/docs/ref#lr.LRParser.configure).

@@ -137,3 +137,3 @@ The argument object maps node selectors to [highlighting

Such a path can be a [node
name](https://lezer.codemirror.net/docs/ref#tree.NodeType.name),
name](https://lezer.codemirror.net/docs/ref#common.NodeType.name),
or multiple node names (or `*` wildcards) separated by slash

@@ -402,16 +402,26 @@ characters, as in `"Block/Declaration/VariableName"`. Such a path

// syntax tree and highlight style.
const treeHighlighter = /*@__PURE__*/Prec.fallback(/*@__PURE__*/ViewPlugin.fromClass(TreeHighlighter, {
const treeHighlighter = /*@__PURE__*/Prec.extend(/*@__PURE__*/ViewPlugin.fromClass(TreeHighlighter, {
decorations: v => v.decorations
}));
const nodeStack = [""];
function highlightTreeRange(tree, from, to, style, span) {
let spanStart = from, spanClass = "";
let cursor = tree.topNode.cursor;
function flush(at, newClass) {
if (spanClass)
span(spanStart, at, spanClass);
spanStart = at;
spanClass = newClass;
class HighlightBuilder {
constructor(at, style, span) {
this.at = at;
this.style = style;
this.span = span;
this.class = "";
}
function node(inheritedClass, depth, scope) {
startSpan(at, cls) {
if (cls != this.class) {
this.flush(at);
if (at > this.at)
this.at = at;
this.class = cls;
}
}
flush(to) {
if (to > this.at && this.class)
this.span(this.at, to, this.class);
}
highlightRange(cursor, from, to, inheritedClass, depth, scope) {
let { type, from: start, to: end } = cursor;

@@ -428,3 +438,3 @@ if (start >= to || end <= from)

for (let tag of rule.tags) {
let st = style(tag, scope);
let st = this.style(tag, scope);
if (st) {

@@ -444,18 +454,47 @@ if (cls)

}
let upto = start;
if (!opaque && cursor.firstChild()) {
this.startSpan(cursor.from, cls);
if (opaque)
return;
let mounted = cursor.tree && cursor.tree.prop(NodeProp.mounted);
if (mounted && mounted.overlay) {
let inner = cursor.node.enter(mounted.overlay[0].from + start, 1);
let hasChild = cursor.firstChild();
for (let i = 0, pos = start;; i++) {
let next = i < mounted.overlay.length ? mounted.overlay[i] : null;
let nextPos = next ? next.from + start : end;
if (nextPos > pos && hasChild) {
while (cursor.from < nextPos) {
this.highlightRange(cursor, pos, nextPos, inheritedClass, depth + 1, scope);
this.startSpan(Math.min(to, cursor.to), cls);
if (cursor.to >= nextPos || !cursor.nextSibling())
break;
}
}
if (!next)
break;
this.highlightRange(inner.cursor, next.from + start, next.to + start, inheritedClass, depth, mounted.tree.type);
pos = next.to + start;
this.startSpan(pos, cls);
}
if (hasChild)
cursor.parent();
}
else if (cursor.firstChild()) {
do {
if (cursor.from > upto && spanClass != cls)
flush(upto, cls);
upto = cursor.to;
node(inheritedClass, depth + 1, scope);
if (cursor.to <= from)
continue;
if (cursor.from >= to)
break;
this.highlightRange(cursor, from, to, inheritedClass, depth + 1, scope);
this.startSpan(Math.min(to, cursor.to), cls);
} while (cursor.nextSibling());
cursor.parent();
}
if (end > upto && spanClass != cls)
flush(upto, cls);
}
node("", 0, tree.type);
flush(to, "");
}
function highlightTreeRange(tree, from, to, style, span) {
let builder = new HighlightBuilder(from, style, span);
builder.highlightRange(tree.cursor(), from, to, "", 0, tree.type);
builder.flush(to);
}
function matchContext(context, stack, depth) {

@@ -462,0 +501,0 @@ if (context.length > depth - 1)

{
"name": "@codemirror/highlight",
"version": "0.18.4",
"version": "0.19.0",
"description": "Syntax highlighting for the CodeMirror code editor",

@@ -29,7 +29,7 @@ "scripts": {

"dependencies": {
"@codemirror/language": "^0.18.0",
"@codemirror/rangeset": "^0.18.0",
"@codemirror/state": "^0.18.0",
"@codemirror/view": "^0.18.0",
"lezer-tree": "^0.13.0",
"@codemirror/language": "^0.19.0",
"@codemirror/rangeset": "^0.19.0",
"@codemirror/state": "^0.19.0",
"@codemirror/view": "^0.19.0",
"@lezer/common": "^0.14.0",
"style-mod": "^4.0.0"

@@ -36,0 +36,0 @@ },

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