@nuasite/cms-marker 0.0.52 → 0.0.53

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
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/cms-marker"
15
15
  },
16
16
  "license": "Apache-2.0",
17
- "version": "0.0.52",
17
+ "version": "0.0.53",
18
18
  "module": "src/index.ts",
19
19
  "types": "src/index.ts",
20
20
  "type": "module",
@@ -2,7 +2,7 @@ import type { ViteDevServer } from 'vite'
2
2
  import { processHtml } from './html-processor'
3
3
  import type { ManifestWriter } from './manifest-writer'
4
4
  import { findCollectionSource, parseMarkdownContent } from './source-finder'
5
- import type { CollectionEntry, CmsMarkerOptions, ComponentDefinition } from './types'
5
+ import type { CmsMarkerOptions, CollectionEntry, ComponentDefinition } from './types'
6
6
 
7
7
  /**
8
8
  * Get the normalized page path from a URL
@@ -90,14 +90,14 @@ export function createDevMiddleware(
90
90
  const requestUrl = req.url || 'unknown'
91
91
 
92
92
  // Intercept response chunks
93
- res.write = function(chunk: any, ...args: any[]) {
93
+ res.write = function (chunk: any, ...args: any[]) {
94
94
  if (chunk) {
95
95
  chunks.push(Buffer.from(chunk))
96
96
  }
97
97
  return true
98
98
  } as any
99
99
 
100
- res.end = function(chunk: any, ...args: any[]) {
100
+ res.end = function (chunk: any, ...args: any[]) {
101
101
  if (chunk) {
102
102
  chunks.push(Buffer.from(chunk))
103
103
  }
@@ -182,14 +182,18 @@ async function searchAstroFile(
182
182
  const matchLength = Math.min(cleanText.length, sectionTextOnly.length)
183
183
  score = 50 + (matchLength / cleanText.length) * 40
184
184
  matched = true
185
- matches.push({ line: i + 1, score, type: 'static' })
185
+ // Find the actual line containing the text
186
+ const actualLine = findLineContainingText(lines, i, 5, textPreview)
187
+ matches.push({ line: actualLine, score, type: 'static' })
186
188
  }
187
189
 
188
190
  // Check for short exact text match (static content)
189
191
  if (!matched && cleanText.length > 0 && cleanText.length <= 10 && sectionTextOnly.includes(cleanText)) {
190
192
  score = 80
191
193
  matched = true
192
- matches.push({ line: i + 1, score, type: 'static' })
194
+ // Find the actual line containing the text
195
+ const actualLine = findLineContainingText(lines, i, 5, cleanText)
196
+ matches.push({ line: actualLine, score, type: 'static' })
193
197
  }
194
198
 
195
199
  // Try matching first few words for longer text (static content)
@@ -198,7 +202,9 @@ async function searchAstroFile(
198
202
  if (firstWords && sectionTextOnly.includes(firstWords)) {
199
203
  score = 40
200
204
  matched = true
201
- matches.push({ line: i + 1, score, type: 'static' })
205
+ // Find the actual line containing the text
206
+ const actualLine = findLineContainingText(lines, i, 5, firstWords)
207
+ matches.push({ line: actualLine, score, type: 'static' })
202
208
  }
203
209
  }
204
210
  }
@@ -459,6 +465,22 @@ function collectSection(lines: string[], startLine: number, numLines: number): s
459
465
  return text
460
466
  }
461
467
 
468
+ /**
469
+ * Find the actual line containing the matched text within a section
470
+ * Returns 1-indexed line number
471
+ */
472
+ function findLineContainingText(lines: string[], startLine: number, numLines: number, searchText: string): number {
473
+ const normalizedSearch = searchText.toLowerCase()
474
+ for (let i = startLine; i < Math.min(startLine + numLines, lines.length); i++) {
475
+ const lineText = stripHtmlTags(lines[i] || '').toLowerCase()
476
+ if (lineText.includes(normalizedSearch)) {
477
+ return i + 1 // Return 1-indexed line number
478
+ }
479
+ }
480
+ // If not found on a specific line, return the opening tag line
481
+ return startLine + 1
482
+ }
483
+
462
484
  /**
463
485
  * Strip HTML tags from text
464
486
  */