@rohal12/spindle-lsp 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +35 -12
- package/dist/bin.js.map +2 -2
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -3006,16 +3006,38 @@ function isInsideAttribute(text, pos) {
|
|
|
3006
3006
|
}
|
|
3007
3007
|
function replaceSpindleTokens(html) {
|
|
3008
3008
|
const tokens = [];
|
|
3009
|
-
const
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3009
|
+
const lines = html.split("\n");
|
|
3010
|
+
const resultLines = [];
|
|
3011
|
+
for (const line of lines) {
|
|
3012
|
+
const trimmed = line.trim();
|
|
3013
|
+
SPINDLE_TOKEN_REGEX.lastIndex = 0;
|
|
3014
|
+
if (!SPINDLE_TOKEN_REGEX.test(trimmed)) {
|
|
3015
|
+
resultLines.push(line);
|
|
3016
|
+
continue;
|
|
3017
|
+
}
|
|
3018
|
+
SPINDLE_TOKEN_REGEX.lastIndex = 0;
|
|
3019
|
+
const withoutSpindle = trimmed.replace(SPINDLE_TOKEN_REGEX, "");
|
|
3020
|
+
const hasHtml = HTML_TAG_REGEX.test(withoutSpindle);
|
|
3021
|
+
if (!hasHtml) {
|
|
3022
|
+
const idx = tokens.length;
|
|
3023
|
+
tokens.push(trimmed);
|
|
3024
|
+
const indent = line.match(/^(\s*)/)?.[1] ?? "";
|
|
3025
|
+
resultLines.push(`${indent}<!--SP:${idx}-->`);
|
|
3026
|
+
} else {
|
|
3027
|
+
SPINDLE_TOKEN_REGEX.lastIndex = 0;
|
|
3028
|
+
const replaced = line.replace(SPINDLE_TOKEN_REGEX, (match, ...args2) => {
|
|
3029
|
+
const matchOffset = args2[args2.length - 2];
|
|
3030
|
+
const idx = tokens.length;
|
|
3031
|
+
tokens.push(match);
|
|
3032
|
+
if (isInsideAttribute(line, matchOffset)) {
|
|
3033
|
+
return `__SP${idx}__`;
|
|
3034
|
+
}
|
|
3035
|
+
return `<!--SP:${idx}-->`;
|
|
3036
|
+
});
|
|
3037
|
+
resultLines.push(replaced);
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
return { text: resultLines.join("\n"), tokens };
|
|
3019
3041
|
}
|
|
3020
3042
|
function restoreSpindleTokens(text, tokens) {
|
|
3021
3043
|
let result = text;
|
|
@@ -3025,11 +3047,12 @@ function restoreSpindleTokens(text, tokens) {
|
|
|
3025
3047
|
}
|
|
3026
3048
|
return result;
|
|
3027
3049
|
}
|
|
3028
|
-
var SPINDLE_TOKEN_REGEX;
|
|
3050
|
+
var SPINDLE_TOKEN_REGEX, HTML_TAG_REGEX;
|
|
3029
3051
|
var init_placeholders = __esm({
|
|
3030
3052
|
"src/plugins/format/placeholders.ts"() {
|
|
3031
3053
|
"use strict";
|
|
3032
|
-
SPINDLE_TOKEN_REGEX = /(?:\{\/[A-Za-z][\w-]*\s*\}|\{(?:[#.][a-zA-Z][\w-]*\s*)*[A-Za-z][\w-]*(?:\s+(?:[^}]|\
|
|
3054
|
+
SPINDLE_TOKEN_REGEX = /(?:\{\/[A-Za-z][\w-]*\s*\}|\{(?:[#.][a-zA-Z][\w-]*\s*)*[A-Za-z][\w-]*(?:\s+(?:[^{}]|\{[^{}]*\})*)?\}|\{[$_@][a-zA-Z][\w.]*\}|\[\[(?:[^\]]*)\]\])/g;
|
|
3055
|
+
HTML_TAG_REGEX = /<\/?[a-zA-Z][\w-]*[\s>/]/;
|
|
3033
3056
|
}
|
|
3034
3057
|
});
|
|
3035
3058
|
|