@vscode/markdown-it-katex
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -169,9 +169,11 @@ "use strict"; | ||
function blockBareMath(state, start, end, silent) { | ||
var lastLine, found = false, pos = state.bMarks[start] + state.tShift[start], max = state.eMarks[start]; | ||
const firstLine = state.src.slice(pos, max); | ||
if (!/^\s*\\begin/.test(firstLine)) { | ||
const startPos = state.bMarks[start] + state.tShift[start]; | ||
const startMax = state.eMarks[start]; | ||
const firstLine = state.src.slice(startPos, startMax); | ||
const beginMatch = firstLine.match(/^\s*\\begin\s*\{([^{}]+)\}/); | ||
if (!beginMatch) { | ||
return false; | ||
} | ||
if (start > 0) { | ||
// Previous line must be blank for bare blocks | ||
// Previous line must be blank for bare blocks. There are instead handled by inlineBareBlock | ||
const previousStart = state.bMarks[start - 1] + state.tShift[start - 1]; | ||
@@ -187,30 +189,28 @@ const previousEnd = state.eMarks[start - 1]; | ||
} | ||
// Handle Single line code block | ||
const beginEndStack = []; | ||
let next = start; | ||
if (!/\\end[\{\}\w]*\s*$/.test(firstLine)) { | ||
let nestingCount = 0; | ||
for (; !found;) { | ||
next++; | ||
if (next >= end) { | ||
break; | ||
let lastLine; | ||
let found = false; | ||
outer: for (; !found; next++) { | ||
if (next >= end) { | ||
break; | ||
} | ||
const pos = state.bMarks[next] + state.tShift[next]; | ||
const max = state.eMarks[next]; | ||
if (pos < max && state.tShift[next] < state.blkIndent) { | ||
// non-empty line with negative indent should stop the list: | ||
break; | ||
} | ||
const line = state.src.slice(pos, max); | ||
for (const match of line.matchAll(/(\\begin|\\end)\s*\{([^{}]+)\}/g)) { | ||
if (match[1] === '\\begin') { | ||
beginEndStack.push(match[2].trim()); | ||
} | ||
pos = state.bMarks[next] + state.tShift[next]; | ||
max = state.eMarks[next]; | ||
if (pos < max && state.tShift[next] < state.blkIndent) { | ||
// non-empty line with negative indent should stop the list: | ||
break; | ||
} | ||
const line = state.src.slice(pos, max); | ||
for (const match of line.matchAll(/\\begin|\\end/g)) { | ||
if (match[0] === '\\begin') { | ||
++nestingCount; | ||
else if (match[1] === '\\end') { | ||
beginEndStack.pop(); | ||
if (!beginEndStack.length) { | ||
lastLine = state.src.slice(pos, max); | ||
found = true; | ||
break outer; | ||
} | ||
else if (match[0] === '\\end') { | ||
--nestingCount; | ||
if (nestingCount < 0) { | ||
const lastPos = max; | ||
lastLine = state.src.slice(pos, lastPos); | ||
found = true; | ||
} | ||
} | ||
} | ||
@@ -222,5 +222,3 @@ } | ||
token.block = true; | ||
token.content = (firstLine && firstLine.trim() ? firstLine + '\n' : '') | ||
+ state.getLines(start + 1, next, state.tShift[start], true) | ||
+ (lastLine && lastLine.trim() ? lastLine : ''); | ||
token.content = (state.getLines(start, next, state.tShift[start], true) + (lastLine ?? '')).trim(); | ||
token.map = [start, state.line]; | ||
@@ -298,2 +296,3 @@ token.markup = '$$'; | ||
const text = state.src.slice(state.pos); | ||
// Make sure this is not a normal bare block | ||
if (!/^\n\\begin/.test(text)) { | ||
@@ -307,17 +306,17 @@ return false; | ||
const lines = text.split(/\n/g).slice(1); | ||
const beginRe = /^\\begin/; | ||
const endRe = /^\\end/; | ||
let nestingCount = 0; | ||
let foundLine = undefined; | ||
for (var i = 0; i < lines.length; ++i) { | ||
let foundLine; | ||
const beginEndStack = []; | ||
outer: for (var i = 0; i < lines.length; ++i) { | ||
const line = lines[i]; | ||
if (beginRe.test(line)) { | ||
++nestingCount; | ||
} | ||
else if (endRe.test(line)) { | ||
--nestingCount; | ||
if (nestingCount <= 0) { | ||
foundLine = i; | ||
break; | ||
for (const match of line.matchAll(/(\\begin|\\end)\s*\{([^{}]+)\}/g)) { | ||
if (match[1] === '\\begin') { | ||
beginEndStack.push(match[2].trim()); | ||
} | ||
else if (match[1] === '\\end') { | ||
beginEndStack.pop(); | ||
if (!beginEndStack.length) { | ||
foundLine = i; | ||
break outer; | ||
} | ||
} | ||
} | ||
@@ -329,8 +328,6 @@ } | ||
const endIndex = lines.slice(0, foundLine + 1).reduce((p, c) => p + c.length, 0) + foundLine + 1; | ||
if (!silent) { | ||
const token = state.push('math_inline_bare_block', 'math', 0); | ||
token.block = true; | ||
token.markup = "$$"; | ||
token.content = text.slice(1, endIndex); | ||
} | ||
const token = state.push('math_inline_bare_block', 'math', 0); | ||
token.block = true; | ||
token.markup = "$$"; | ||
token.content = text.slice(1, endIndex); | ||
state.pos = state.pos + endIndex; | ||
@@ -337,0 +334,0 @@ return true; |
{ | ||
"name": "@vscode/markdown-it-katex", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Markdown-it plugin that provides VS Code's KaTeX support", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
23931
468