@rohal12/spindle-lsp 0.5.2 → 0.5.3

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
@@ -2861,6 +2861,20 @@ function segmentRegions(body) {
2861
2861
  regions.push({ type: "script", lines: scriptLines });
2862
2862
  continue;
2863
2863
  }
2864
+ if (/^<svg(\s|>)/i.test(trimmed)) {
2865
+ const svgLines = [line];
2866
+ i++;
2867
+ while (i < lines.length && !/<\/svg>/i.test(lines[i])) {
2868
+ svgLines.push(lines[i]);
2869
+ i++;
2870
+ }
2871
+ if (i < lines.length) {
2872
+ svgLines.push(lines[i]);
2873
+ i++;
2874
+ }
2875
+ regions.push({ type: "svg", lines: svgLines });
2876
+ continue;
2877
+ }
2864
2878
  if (/^<([a-zA-Z][\w-]*)/.test(trimmed)) {
2865
2879
  const tagMatch = trimmed.match(/^<([a-zA-Z][\w-]*)/);
2866
2880
  const tagName = tagMatch[1].toLowerCase();
@@ -3004,6 +3018,22 @@ function isInsideAttribute(text, pos) {
3004
3018
  }
3005
3019
  return inQuote;
3006
3020
  }
3021
+ function replaceSvgBlocks(html) {
3022
+ const tokens = [];
3023
+ const result = html.replace(/<svg[\s>][\s\S]*?<\/svg>/gi, (match) => {
3024
+ const idx = tokens.length;
3025
+ tokens.push(match);
3026
+ return `<!--SVG:${idx}-->`;
3027
+ });
3028
+ return { text: result, tokens };
3029
+ }
3030
+ function restoreSvgBlocks(text, tokens) {
3031
+ let result = text;
3032
+ for (let i = 0; i < tokens.length; i++) {
3033
+ result = result.replace(`<!--SVG:${i}-->`, tokens[i]);
3034
+ }
3035
+ return result;
3036
+ }
3007
3037
  function replaceSpindleTokens(html) {
3008
3038
  const tokens = [];
3009
3039
  const lines = html.split("\n");
@@ -3129,11 +3159,17 @@ async function formatDocument(text, options) {
3129
3159
  resultLines.push(lastLine);
3130
3160
  continue;
3131
3161
  }
3162
+ if (region.type === "svg") {
3163
+ resultLines.push(...region.lines);
3164
+ continue;
3165
+ }
3132
3166
  if (region.type === "html") {
3133
3167
  const htmlText = region.lines.join("\n");
3134
- const { text: placeholdered, tokens } = replaceSpindleTokens(htmlText);
3168
+ const { text: svgPlaceholdered, tokens: svgTokens } = replaceSvgBlocks(htmlText);
3169
+ const { text: placeholdered, tokens } = replaceSpindleTokens(svgPlaceholdered);
3135
3170
  const formatted = await formatHTML(placeholdered);
3136
- const restored = restoreSpindleTokens(formatted.trim(), tokens);
3171
+ const restoredSpindle = restoreSpindleTokens(formatted.trim(), tokens);
3172
+ const restored = restoreSvgBlocks(restoredSpindle, svgTokens);
3137
3173
  for (const fLine of restored.split("\n")) {
3138
3174
  resultLines.push(fLine);
3139
3175
  }