@herb-tools/formatter 0.8.0 → 0.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herb-tools/formatter",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Auto-formatter for HTML+ERB templates with intelligent indentation, line wrapping, and ERB-aware pretty-printing.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://herb-tools.dev",
@@ -35,10 +35,10 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@herb-tools/config": "0.8.0",
39
- "@herb-tools/core": "0.8.0",
40
- "@herb-tools/printer": "0.8.0",
41
- "@herb-tools/rewriter": "0.8.0"
38
+ "@herb-tools/config": "0.8.1",
39
+ "@herb-tools/core": "0.8.1",
40
+ "@herb-tools/printer": "0.8.1",
41
+ "@herb-tools/rewriter": "0.8.1"
42
42
  },
43
43
  "files": [
44
44
  "package.json",
@@ -194,7 +194,9 @@ export function isERBTag(text: string): boolean {
194
194
  * Check if a string ends with an ERB tag
195
195
  */
196
196
  export function endsWithERBTag(text: string): boolean {
197
- return /%>$/.test(text.trim())
197
+ const trimmed = text.trim()
198
+
199
+ return /%>$/.test(trimmed) || /%>\S+$/.test(trimmed)
198
200
  }
199
201
 
200
202
  /**
@@ -1862,7 +1862,7 @@ export class FormatPrinter extends Printer {
1862
1862
  const firstWord = words[0]
1863
1863
  const firstChar = firstWord[0]
1864
1864
 
1865
- if (!/[a-zA-Z0-9.!?:;]/.test(firstChar)) {
1865
+ if (/\s/.test(firstChar)) {
1866
1866
  return false
1867
1867
  }
1868
1868
 
@@ -1879,6 +1879,11 @@ export class FormatPrinter extends Printer {
1879
1879
  unit: { content: remainingText, type: 'text', isAtomic: false, breaksFlow: false },
1880
1880
  node: textNode
1881
1881
  })
1882
+ } else if (endsWithWhitespace(textNode.content)) {
1883
+ result.push({
1884
+ unit: { content: ' ', type: 'text', isAtomic: false, breaksFlow: false },
1885
+ node: textNode
1886
+ })
1882
1887
  }
1883
1888
 
1884
1889
  return true
@@ -1955,10 +1960,8 @@ export class FormatPrinter extends Printer {
1955
1960
  const hasWhitespace = this.hasWhitespaceBeforeNode(children, lastProcessedIndex, index, child)
1956
1961
  const lastUnit = result[result.length - 1]
1957
1962
  const lastIsAtomic = lastUnit.unit.isAtomic && (lastUnit.unit.type === 'erb' || lastUnit.unit.type === 'inline')
1958
- const trimmed = child.content.trim()
1959
- const startsWithClosingPunct = trimmed.length > 0 && /^[.!?:;]/.test(trimmed)
1960
1963
 
1961
- if (lastIsAtomic && (!hasWhitespace || startsWithClosingPunct) && this.tryMergeTextAfterAtomic(result, child)) {
1964
+ if (lastIsAtomic && !hasWhitespace && this.tryMergeTextAfterAtomic(result, child)) {
1962
1965
  return
1963
1966
  }
1964
1967
  }