punctilio 4.3.0 → 4.3.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/constants.d.ts +4 -11
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -13
- package/dist/constants.js.map +1 -1
- package/dist/dashes.d.ts +1 -1
- package/dist/dashes.d.ts.map +1 -1
- package/dist/dashes.js +995 -140
- package/dist/dashes.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prose-view.d.ts +10 -0
- package/dist/prose-view.d.ts.map +1 -1
- package/dist/prose-view.js +26 -0
- package/dist/prose-view.js.map +1 -1
- package/dist/quote-classifier.d.ts.map +1 -1
- package/dist/quote-classifier.js +1 -9
- package/dist/quote-classifier.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +4 -14
- package/src/dashes.ts +1025 -197
- package/src/index.ts +1 -0
- package/src/prose-view.ts +30 -0
- package/src/quote-classifier.ts +1 -10
package/src/index.ts
CHANGED
package/src/prose-view.ts
CHANGED
|
@@ -247,6 +247,16 @@ function matchContainsBoundary(match: RegExpExecArray, view: ProseView): boolean
|
|
|
247
247
|
return false
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
/** Count of node boundaries that fall at exactly `offset` (empty nodes stack). */
|
|
251
|
+
export function boundaryCountAt(view: ProseView, offset: number): number {
|
|
252
|
+
let count = 0
|
|
253
|
+
for (const boundary of view.boundaries) {
|
|
254
|
+
if (boundary === offset) count++
|
|
255
|
+
else if (boundary > offset) break
|
|
256
|
+
}
|
|
257
|
+
return count
|
|
258
|
+
}
|
|
259
|
+
|
|
250
260
|
export function replaceAllInView(
|
|
251
261
|
view: ProseView,
|
|
252
262
|
regex: RegExp,
|
|
@@ -281,6 +291,26 @@ export function replaceAllInView(
|
|
|
281
291
|
}
|
|
282
292
|
}
|
|
283
293
|
|
|
294
|
+
/**
|
|
295
|
+
* Splits sentinel-marked text on the separator, builds a ProseView over the
|
|
296
|
+
* fragments, runs `run` against the clean-text view, commits the queued edits,
|
|
297
|
+
* and rejoins the fragments with the separator. The separator count is
|
|
298
|
+
* preserved exactly: each fragment maps to one source node, and `commit()`
|
|
299
|
+
* never creates or destroys node boundaries.
|
|
300
|
+
*/
|
|
301
|
+
export function withProseView(
|
|
302
|
+
markedText: string,
|
|
303
|
+
separator: string,
|
|
304
|
+
run: (view: ProseView) => void,
|
|
305
|
+
): string {
|
|
306
|
+
const fragments = separator.length > 0 ? markedText.split(separator) : [markedText]
|
|
307
|
+
const nodes: ProseNode[] = fragments.map((value) => ({ value }))
|
|
308
|
+
const view = buildProseView(nodes)
|
|
309
|
+
run(view)
|
|
310
|
+
view.commit()
|
|
311
|
+
return nodes.map((node) => node.value).join(separator)
|
|
312
|
+
}
|
|
313
|
+
|
|
284
314
|
export function runLegacyPass(
|
|
285
315
|
view: ProseView,
|
|
286
316
|
passFn: (markedText: string) => string,
|
package/src/quote-classifier.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LATIN_LETTERS, TERMINAL_PUNCTUATION, UNICODE_SYMBOLS } from "./constants.js"
|
|
2
|
-
import {
|
|
2
|
+
import { type ProseView, withProseView } from "./prose-view.js"
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
EM_DASH,
|
|
@@ -860,15 +860,6 @@ function queueRenderEdits(view: ProseView, items: Item[], table: Record<QuoteRol
|
|
|
860
860
|
// Public engine entry points
|
|
861
861
|
// ---------------------------------------------------------------------------
|
|
862
862
|
|
|
863
|
-
function withProseView(markedText: string, separator: string, run: (view: ProseView) => void): string {
|
|
864
|
-
const fragments = separator.length > 0 ? markedText.split(separator) : [markedText]
|
|
865
|
-
const nodes: ProseNode[] = fragments.map((value) => ({ value }))
|
|
866
|
-
const view = buildProseView(nodes)
|
|
867
|
-
run(view)
|
|
868
|
-
view.commit()
|
|
869
|
-
return nodes.map((node) => node.value).join(separator)
|
|
870
|
-
}
|
|
871
|
-
|
|
872
863
|
/**
|
|
873
864
|
* The quote/apostrophe role classifier: one boundary-aware scan over the
|
|
874
865
|
* clean text replaces the v4 ordered regex pipeline.
|