Matthew Butterick 10 years ago
commit 8235737837

@ -115,6 +115,8 @@ Sometimes you need @racket[hyphenatef] to prevent unintended consequences. For i
(hyphenatef "Hufflepuff golfing final on Tuesday" no-ligs? #\-)
]
@margin-note{``Wouldn't it be better to exclude certain pairs of letters rather than whole words?'' Yes. But for now, not supported.}
It's possible to do fancier kinds of hyphenation restrictions that take account of context, like not hyphenating the last word of a paragraph. But @racket[hyphenatef] only operates on words. So you'll have to write some fancier code. Separate out the words eligible for hyphenation, and then send them through good old @racket[hyphenate].
@defproc[

@ -0,0 +1,39 @@
#lang racket/base
(require "main.rkt")
(require xml)
#|
The following grammar describes expressions that create X-expressions:
xexpr = string
| (list symbol (list (list symbol string) ...) xexpr ...)
| (cons symbol (list xexpr ...))
| symbol
| valid-char?
| cdata
| misc
|#
;; recursively hyphenate strings within xexpr
;; todo: add exclusion #:only [only-proc (λ(x) x)]
(define (hyphenate-xexpr x )
(define exclusions '(style script)) ; omit these from ever being hyphenated
(cond
; todo: the only-proc semantics are illogical.
; main issue: keep it out of tags like <style> that parse as textual elements, but are not.
; So two choices, opt-out or opt-in.
; Problem with opt-out: is set of outlier tags like <style> well-defined?
; Won't it make hyphenation naturally overinclusive?
; Problem with opt-in: conceals a lot of tags that naturally live inside other tags
; only reaches text at the "root level" of the tag.
[(tagged-xexpr? x) (if (and (only-proc x) (not ((car x) . in? . exclusions)))
(map-xexpr-elements hyphenate x)
(map-xexpr-elements (λ(x) (if (tagged-xexpr? x) (hyphenate x) x)) x))] ; only process subxexprs
[(string? x) (hyphenate-string x)]
[else x]))
Loading…
Cancel
Save