@expressive-code/plugin-shiki
Advanced tools
Comparing version 0.17.0 to 0.18.0
@@ -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, |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39190
370
+ Added@expressive-code/core@0.18.1(transitive)
- Removed@expressive-code/core@0.17.0(transitive)