diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index e3eed75..6c03fde 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1484775689 +1488121531 diff --git a/pollen/scribblings/typography.scrbl b/pollen/scribblings/typography.scrbl index ed30011..f8aac10 100644 --- a/pollen/scribblings/typography.scrbl +++ b/pollen/scribblings/typography.scrbl @@ -16,16 +16,29 @@ Quick & dirty utilities. I use them, but I haven't tested them with enough edge @defproc[ (smart-quotes -[xexpr (or/c string? txexpr?)]) -(or/c string? txexpr?)] -Convert straight quotes in @racket[_xexepr] to curly according to American English conventions. +[xexpr (or/c string? txexpr?)] +[#:apostophe apostrophe-str string? "’"] +[#:single-open single-open-str string? "‘"] +[#:single-close single-close-str string? "’"] +[#:double-open double-open-str string? "“"] +[#:double-close double-close-str string? "”"]) +(or/c string? txexpr?)]{ + +Convert straight quotes in @racket[xexpr] to curly. By default, American English curly quotes are used. The optional keyword arguments can be used to set different quotes suited to other languages or script systems. @examples[#:eval my-eval (define tricky-string "\"Why,\" she could've asked, \"are we in O‘ahu watching 'Mame'?\"") (display tricky-string) (display (smart-quotes tricky-string)) +(display (smart-quotes tricky-string + #:double-open "«" #:double-close "»" + #:single-open "‹" #:single-close "›")) +(display (smart-quotes tricky-string + #:double-open "„" #:double-close "”" + #:single-open "‚" #:single-close "’")) ] +} @defproc[ (smart-dashes diff --git a/pollen/unstable/typography.rkt b/pollen/unstable/typography.rkt index e0b992c..61f61b8 100644 --- a/pollen/unstable/typography.rkt +++ b/pollen/unstable/typography.rkt @@ -20,22 +20,38 @@ (module-test-external (check-equal? (smart-dashes "I had --- maybe 13 -- 20 --- hob-nobs.") "I had—maybe 13–20—hob-nobs.") - (check-equal? (smart-quotes "\"Why,\" she could've asked, \"are we in O‘ahu watching 'Mame'?\"") + (define tricky-string "\"Why,\" she could've asked, \"are we in O‘ahu watching 'Mame'?\"") + (check-equal? (smart-quotes tricky-string) "“Why,” she could’ve asked, “are we in O‘ahu watching ‘Mame’?”") + (check-equal? (smart-quotes tricky-string + #:apostrophe "zing" + #:double-open "«" #:double-close "»" + #:single-open "‹" #:single-close "›") + "«Why,» she couldzingve asked, «are we in O‘ahu watching ‹Mame›?»") (check-equal? (smart-quotes "\"\'Impossible.\' Yes.\"") "“‘Impossible.’ Yes.”") (check-equal? (smart-quotes '(div "don'" (em "t"))) '(div "don’" (em "t"))) (check-equal? (smart-quotes '(div "do '" (em "not'"))) '(div "do ‘" (em "not’")))) -(define+provide/contract (smart-quotes x) - ((or/c string? txexpr?) . -> . (or/c string? txexpr?)) +(define+provide/contract (smart-quotes x + #:apostrophe [apostrophe-str "’"] + #:single-open [single-open-str "‘"] + #:single-close [single-close-str "’"] + #:double-open [double-open-str "“"] + #:double-close [double-close-str "”"]) + (((or/c string? txexpr?)) + (#:apostrophe string? + #:single-open string? + #:single-close string? + #:double-open string? + #:double-close string?) . ->* . (or/c string? txexpr?)) (define quotes - '((#px"(?<=\\w)'(?=\\w)" "’") ; apostrophe - (#px"(?