add `smart-ellipses`

dev-render-audit
Matthew Butterick 6 years ago
parent be47536c33
commit 37c29a3909

@ -1 +1 @@
1559944660 1560281665

@ -54,6 +54,19 @@ In @racket[_str], convert three hyphens to an em dash, and two hyphens to an en
] ]
@defproc[
(smart-ellipses
[str string?])
string?]
In @racket[_str], convert three periods to an ellipsis.
@examples[#:eval my-eval
(define tricky-string "I had a few ... OK, like 6--8 ... thin mints.")
(display tricky-string)
(display (smart-ellipses tricky-string))
]
@defproc[ @defproc[
(wrap-hanging-quotes (wrap-hanging-quotes

@ -18,6 +18,11 @@
(#px"[\\s#\u00A0]*(--|)[\\s#\u00A0]*" ""))) ; en dash (#px"[\\s#\u00A0]*(--|)[\\s#\u00A0]*" ""))) ; en dash
((make-replacer dashes) str)) ((make-replacer dashes) str))
(define+provide/contract (smart-ellipses str)
(string? . -> . string?)
(define triple-dot '((#px"\\.{3}" "")))
((make-replacer triple-dot) str))
(module-test-external (module-test-external
(check-equal? (smart-dashes "I had --- maybe 13 -- 20 --- hob-nobs.") "I had—maybe 1320—hob-nobs.") (check-equal? (smart-dashes "I had --- maybe 13 -- 20 --- hob-nobs.") "I had—maybe 1320—hob-nobs.")
(define tricky-string "\"Why,\" she could've asked, \"are we in Oahu watching 'Mame'?\"") (define tricky-string "\"Why,\" she could've asked, \"are we in Oahu watching 'Mame'?\"")

Loading…
Cancel
Save