@rohal12/spindle-lsp 0.5.0 → 0.5.2

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 CHANGED
@@ -2880,7 +2880,7 @@ function segmentRegions(body) {
2880
2880
  i++;
2881
2881
  while (i < lines.length && depth > 0) {
2882
2882
  htmlLines.push(lines[i]);
2883
- const opens = (lines[i].match(new RegExp(`<${tagName}[\\s>]`, "gi")) ?? []).length;
2883
+ const opens = (lines[i].match(new RegExp(`<${tagName}(?:[\\s>]|$)`, "gi")) ?? []).length;
2884
2884
  const closes = (lines[i].match(new RegExp(`</${tagName}\\s*>`, "gi")) ?? []).length;
2885
2885
  depth += opens - closes;
2886
2886
  i++;
@@ -3006,16 +3006,38 @@ function isInsideAttribute(text, pos) {
3006
3006
  }
3007
3007
  function replaceSpindleTokens(html) {
3008
3008
  const tokens = [];
3009
- const text = html.replace(SPINDLE_TOKEN_REGEX, (match, ...args2) => {
3010
- const offset = args2[args2.length - 2];
3011
- const idx = tokens.length;
3012
- tokens.push(match);
3013
- if (isInsideAttribute(html, offset)) {
3014
- return `__SP${idx}__`;
3015
- }
3016
- return `<!--SP:${idx}-->`;
3017
- });
3018
- return { text, tokens };
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+(?:[^}]|\}(?=[^}]))*?)?\}|\{[$_@][a-zA-Z][\w.]*\}|\[\[(?:[^\]]*)\]\])/g;
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