69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
+
|
html-index
html-figure
html-figure-@2x
html-image-link
html-dialogue
html-say
html-saylines
html-magick
html-verse
html-attrib
html-link
html-xref
html-url
html-fn
html-fndef
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
[italic? (assoc 'italic? attrs)]
[pre-attrs (cond [italic? '([class "verse"] [style "font-style: italic"])]
[else '([class "verse"])])]
[pre-title (cond [(string>? title "") `(p [[class "verse-heading"]] ,title)]
[else ""])])
`(div [[class "poem"]] ,pre-title (pre ,pre-attrs ,@elems))))
(define (html-magick . elems)
(txexpr
'div '([class "antique"])
(decode-elements elems #:string-proc (λ (s) (regexp-replace* #px"(?<!f)s(?![fkb\\s]|$)" s "ſ")))))
(module+ test
(require rackunit)
; round s at the end of a word
(check-equal? (html-magick "is") '(div [[class "antique"]] "is"))
; round s before/after f
(check-equal? (html-magick "offset, satisfaction") '(div [[class "antique"]] "offset, ſatisfaction"))
; long s before hyphen
(check-equal? (html-magick "Shafts-bury") '(div [[class "antique"]] "Shaftſ-bury"))
; round s before k or b (17th-century rules)
(check-equal? (html-magick "ask, husband") '(div [[class "antique"]] "ask, husband"))
; long s everywhere else
(check-equal? (html-magick "song, substitutes") '(div [[class "antique"]] "ſong, ſubſtitutes"))
;; Nested elements
(check-equal?
(html-magick '(root "This is " (a [[href "class"]] (b "song, substitutes"))))
'(div [[class "antique"]] (root "This is " (a [[href "class"]] (b "ſong, ſubſtitutes"))))))
(define html-attrib (default-tag-function 'div #:class "attrib"))
;; (Private) Get the dimensions of an image file
(define (get-image-size filepath)
(define bmp (make-object bitmap% filepath))
(list (send bmp get-width) (send bmp get-height)))
|