From 37c29a39096ce4dc75e57c840bb1e3d23dc0cdb6 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 11 Jun 2019 12:34:25 -0700 Subject: [PATCH] add `smart-ellipses` --- pollen/private/ts.rktd | 2 +- pollen/scribblings/typography.scrbl | 13 +++++++++++++ pollen/unstable/typography.rkt | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index ecf0e2f..a5683c7 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1559944660 +1560281665 diff --git a/pollen/scribblings/typography.scrbl b/pollen/scribblings/typography.scrbl index f8aac10..d05ae16 100644 --- a/pollen/scribblings/typography.scrbl +++ b/pollen/scribblings/typography.scrbl @@ -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[ (wrap-hanging-quotes diff --git a/pollen/unstable/typography.rkt b/pollen/unstable/typography.rkt index bda95f8..549325d 100644 --- a/pollen/unstable/typography.rkt +++ b/pollen/unstable/typography.rkt @@ -18,6 +18,11 @@ (#px"[\\s#\u00A0]*(--|–)[\\s#\u00A0]*" "–"))) ; en dash ((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 (check-equal? (smart-dashes "I had --- maybe 13 -- 20 --- hob-nobs.") "I had—maybe 13–20—hob-nobs.") (define tricky-string "\"Why,\" she could've asked, \"are we in O‘ahu watching 'Mame'?\"")