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

@expressive-code/plugin-shiki

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@expressive-code/plugin-shiki - npm Package Compare versions

Comparing version 0.17.0 to 0.18.0

37

dist/index.js

@@ -37,4 +37,6 @@ // src/index.ts

}
const tokenLines = highlighter.codeToThemedTokens(code, codeBlock.language, theme.name, { includeExplanation: false });
const tokenLines = codeBlock.language === "ansi" ? highlighter.ansiToThemedTokens(code, theme.name) : highlighter.codeToThemedTokens(code, codeBlock.language, theme.name, { includeExplanation: false });
tokenLines.forEach((line, lineIndex) => {
if (codeBlock.language === "ansi")
removeAnsiSequencesFromCodeLine(codeLines[lineIndex], line);
let charIndex = 0;

@@ -67,2 +69,35 @@ line.forEach((token) => {

}
function removeAnsiSequencesFromCodeLine(codeLine, lineTokens) {
const newLine = lineTokens.map((token) => token.content).join("");
const rangesToRemove = getRemovedRanges(codeLine.text, newLine);
for (let index = rangesToRemove.length - 1; index >= 0; index--) {
const [start, end] = rangesToRemove[index];
codeLine.editText(start, end, "");
}
}
function getRemovedRanges(original, edited) {
const ranges = [];
let from = -1;
let orgIdx = 0;
let edtIdx = 0;
while (orgIdx < original.length && edtIdx < edited.length) {
if (original[orgIdx] !== edited[edtIdx]) {
if (from === -1)
from = orgIdx;
orgIdx++;
} else {
if (from > -1) {
ranges.push([from, orgIdx]);
from = -1;
}
orgIdx++;
edtIdx++;
}
}
if (edtIdx < edited.length)
throw new Error(`Edited string contains characters not present in original (${JSON.stringify({ original, edited })})`);
if (orgIdx < original.length)
ranges.push([orgIdx, original.length]);
return ranges;
}
export {

@@ -69,0 +104,0 @@ loadShikiTheme,

6

package.json
{
"name": "@expressive-code/plugin-shiki",
"version": "0.17.0",
"version": "0.18.0",
"description": "Shiki syntax highlighting plugin for Expressive Code, a text marking & annotation engine for presenting source code on the web.",

@@ -26,3 +26,3 @@ "keywords": [],

"dependencies": {
"@expressive-code/core": "^0.17.0",
"@expressive-code/core": "^0.18.0",
"shiki": "^0.14.1"

@@ -32,3 +32,3 @@ },

"hast-util-to-html": "^8.0.4",
"@internal/test-utils": "^0.2.10"
"@internal/test-utils": "^0.2.11"
},

@@ -35,0 +35,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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