-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscribble.rkt
266 lines (233 loc) · 10.2 KB
/
scribble.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#lang at-exp racket/base
(provide defmapping defhzify section+elemref section+autotag
eleph-note elucidate
stands-for whstands-for
same-as-cnchar same-as-cnchar-but same-as-cnchar-and
simplified-from-cnchar simplified-from-cnchar-but simplified-from-cnchar-and
modernly-simplifies anciently-simplifies
simplf-from
modernly-means mingly-resembles
ori-esp-means
;; defradical defcomponent defcharacter defhybrid
defradical defcomponent defsuffix defprefix definsert defhas
defzi defzis defzi/puauni defzi/sub defcompost
zi zi-ref zitools-ref
short-for-code short-for-racket
)
(require scribble/manual racket/string scribble/core
scribble/html-properties
(for-syntax racket/base racket/string racket/list
"private/zitable.rkt"))
(define-syntax-rule (defhzify cnid rsn enid)
(defthing #:kind "word" cnid (unsyntax (racketidfont rsn)) #:value enid)
)
(define-syntax (defradical stx)
(syntax-case stx ()
[(_ zi)
(with-syntax ([str-zi (symbol->string (syntax-e #'zi))])
#'(elem (elemtag str-zi (bold (litchar str-zi))) (hspace 1) "as radical"))
])
)
(define-syntax (defcomponent stx)
(syntax-case stx ()
[(_ zi)
(with-syntax ([str-zi (symbol->string (syntax-e #'zi))])
#'(elem (elemtag str-zi (bold (litchar str-zi))) (hspace 1) "as component" ))
])
)
(define-syntax (defsuffix stx)
(syntax-case stx ()
[(_ zi)
(with-syntax ([str-zi (if (number? (syntax-e #'zi))
(number->string (syntax-e #'zi))
(symbol->string (syntax-e #'zi)))])
#'(elem "suffixed with" (hspace 1) (elemtag str-zi (bold (litchar str-zi)))))
])
)
(define-syntax (defprefix stx)
(syntax-case stx ()
[(_ zi)
(with-syntax ([str-zi (if (number? (syntax-e #'zi))
(number->string (syntax-e #'zi))
(symbol->string (syntax-e #'zi)))])
#'(elem "prefixed with" (hspace 1) (elemtag str-zi (bold (litchar str-zi)))))
])
)
(define-syntax (definsert stx)
(syntax-case stx ()
[(_ zi)
(with-syntax ([str-zi (symbol->string (syntax-e #'zi))])
#'(elem "inserted with" (hspace 1) (elemtag str-zi (bold (litchar str-zi)))))
])
)
(define-syntax (defhas stx)
(syntax-case stx ()
[(_ zi)
(with-syntax ([str-zi (symbol->string (syntax-e #'zi))])
#'(elem "has" (hspace 1) (elemtag str-zi (bold (litchar str-zi)))))
])
)
(define-syntax (section+elemref stx)
(syntax-case stx ()
[(_ pars ...)
(datum->syntax stx `(begin
,(cons 'section #'(pars ...))
,@(for/list ([e (string-split (syntax-e (last (syntax-e #'(pars ...)))) #rx"(、|,|:)")]) (list 'elemtag (string-trim e))) ; fix last, when source code includes newlines
(linebreak)))]
)
)
(define-syntax (defmapping stx)
(define (gen-defhzify ecr)
(define enid (car ecr))
(define cnid (cadr ecr))
(define raw-exploded
(cond [(and (> (length ecr) 2)
(list? (caddr ecr)))
(map (lambda (e) `(zi ,(cond
[(symbol? e) e]
[(string? e) (string->symbol e)]
[(list? e) 'needtofix]
[else 'needtofix])))
(caddr ecr))]
[(and (= (length ecr) 2)
(string-contains? (symbol->string cnid) "/"))
(add-between (map (lambda (e) `(racket ,(string->symbol e)))
(string-split (symbol->string cnid) "/"))
`(zi /))]
[(= (length ecr) 2)
(map (lambda (e) `(zi ,(string->symbol e)))
(filter non-empty-string? (string-split (symbol->string cnid) "")))]
[else '()]))
(define exploded `(elem ,@(add-between raw-exploded " + ")))
(datum->syntax stx `(defhzify ,cnid ,exploded ,enid)))
(syntax-case stx ()
[(_ path)
(with-syntax ([(defth ...)
(map gen-defhzify
(get-zis (syntax-e #'path)))])
#'(deftogether
(defth ...)))]
)
)
(define (zitools-ref zi [lit-zi zi])
(hyperlink (string-append "https://zi.tools/zi/" zi) lit-zi #:style (style #f (list (attributes '([target . "_blank"] [style . "background: #ebf5fb; "]))))))
(define (defzi0/puauni tag) ;; unicode from pivate use areas
(elemtag tag (elem (bold (litchar tag)) ":" (hspace 1) "PUA unicode, especially designs for ming-lang.")))
(define (defzi0 tag . content)
(elemtag tag (elem (bold (litchar tag)) ":" (hspace 1) content)))
(define-syntax (defzi/puauni stx)
(syntax-case stx ()
[(_ zi content ...)
(with-syntax ([str-zi (symbol->string (syntax-e #'zi))])
#'(elemtag str-zi (elem (bold (racket (code:hilite zi))) ":" (hspace 1) "PUA unicode, especially designs for ming-lang.")))
])
)
(define-syntax (defzi/sub stx)
(syntax-case stx ()
[(_ zi content ...)
(with-syntax ([str-zi (symbol->string (syntax-e #'zi))])
#'(elem #:style (style #f (list (attributes '([style . "margin-bottom: 0; "]))))
(elemtag str-zi (elem (bold (racket (code:hilite zi))) ":" (hspace 1) content ...))))
])
)
(define-for-syntax (r-background-label label)
`(elem #:style (style #f (list (alt-tag "div") (attributes '([class . "RBackgroundLabelInner"]))))
,label)
)
(define-syntax (defzis stx)
(define (zis-of-str stx-zis)
(string-split (symbol->string (syntax-e stx-zis)) "/"))
(define (gen-elemtag z)
`(elemtag ,z (bold (racket (code:hilite ,(string->symbol z))))))
(define (gen-elemtags zis)
(datum->syntax stx (cons 'elem (add-between (map gen-elemtag zis) "/"))))
(syntax-case stx ()
[(_ zis content ...)
#`(elem #:style (style #f (list (alt-tag "p") (attributes '([class . "boxed"]))))
#,(gen-elemtags (zis-of-str #'zis)) ":" (hspace 1) content ... #,(r-background-label "ideograph"))
])
)
(define-syntax (defzi stx)
(syntax-case stx ()
[(_ zi content ...)
(with-syntax ([str-zi (symbol->string (syntax-e #'zi))])
#`(elem #:style (style #f (list (alt-tag "div") (attributes '([class . "boxed"] [style . "margin-top: 1em; margin-bottom: 1em; "]))))
(elemtag str-zi (elem (bold (racket (code:hilite zi))) ":" (hspace 1) content ...
(elem #:style (style #f (list (alt-tag "div") (attributes '([class . "RBackgroundLabel SIEHidden"]))))
#,(r-background-label "ideograph"))
))))
])
)
(define-syntax (defcompost stx) ;; define compostion
(define (gen-parts ps)
(datum->syntax stx (cons 'elem (add-between (map (lambda (p) `(zi ,p)) ps) " + "))))
(syntax-case stx ()
[(_ zi (parts ...) content ...)
#`(defzi zi #,(gen-parts (syntax->datum #'(parts ...))) "." (hspace 1) content ...)
])
)
(define-syntax (zi stx) ;; zi shorts for hanzi, means chinese char.
(syntax-case stx ()
[(_ z)
(with-syntax ([str-z (symbol->string (syntax-e #'z))])
#'(zi-ref str-z))
])
)
(define (zi-ref c) ;; zi shorts for hanzi, means chinese char.
(elem #:style (style #f (list (attributes '([style . "background: #f5eef8; "])))) ; [class . "highlighted"]
(elemref c (racketplainfont c)))
)
(define (section+autotag . content)
(define tag (string-join content ""))
(section #:tag tag content))
(define (stands-for . content)
(elem "stands for" (hspace 1) @(elucidate content)))
(define (whstands-for . content)
(elem "which stands for" (hspace 1) @(elucidate content)))
(define (same-as-cnchar-and cnchar ori-meaning standing)
(elem "same as cnchar " @zitools-ref[cnchar] ", which means " @elucidate{@ori-meaning} ", and especially " @stands-for[@standing] " in Ming"))
(define (same-as-cnchar-but cnchar ori-meaning standing)
(elem "same as cnchar " @zitools-ref[cnchar] ", which means " @elucidate{@ori-meaning} ", but borrowed to " @stands-for[@standing] " in Ming"))
(define (same-as-cnchar cnchar meaning)
(elem "same as cnchar " (hspace 1) @zitools-ref[cnchar] ", " @stands-for[@meaning] " in Ming"))
(define (simplified-from-cnchar-and cnchar ori-meaning meaning)
(elem "simplified from cnchar " (hspace 1) @zitools-ref[cnchar] ", which means " @elucidate{@ori-meaning} ", and especially " @stands-for[@meaning] " in Ming"))
(define (simplified-from-cnchar-but cnchar ori-meaning meaning)
(elem "simplified from cnchar " (hspace 1) @zitools-ref[cnchar] ", which means " @elucidate{@ori-meaning} ", but borrowed to " @stands-for[@meaning] " in Ming"))
(define (simplified-from-cnchar cnchar meaning)
(elem "simplified from cnchar " (hspace 1) @zitools-ref[cnchar] ", " @stands-for[@meaning] " in Ming"))
(define (eleph-note . content) ;; 像注, elephant in chinese is wrote as 象, and 像 means like
(margin-note (elem "🐘" (hspace 1) content))) ;; 💡
(define (elucidate . content) ;; 释义
(elem (italic content)))
(define (modernly-means elucidation . content)
@elem{means @elucidate{@elucidation} in modern chinese. @content}
)
(define (mingly-resembles zi elucidation . content)
@elem{resembles @zi-ref[@zi], stands for @elucidate{@elucidation} in Ming. @content}
)
(define (modernly-simplifies zi elucidation . content)
@elem{simplified from @(litchar zi), which means @(elucidate elucidation) in modern chinese. @content}
)
(define (anciently-simplifies zi elucidation ming-elu . content)
@elem{simplified from @litchar{@zi} in ancient chinese, means @elucidate{@elucidation}, stands for @elucidate{@ming-elu} in Ming. @content}
)
(define (ori-esp-means ori-elu esp-elu . content)
@elem{originally means @elucidate{@ori-elu}, stands for @elucidate{@esp-elu} in Ming. @content}
)
(define (simplf-from zi)
@elem{simplified from @litchar{@zi}}
)
(define-syntax (short-for-code stx)
(syntax-case stx ()
[(_ c ...)
#'(elem "Shorts for " (code c ...))
])
)
(define-syntax (short-for-racket stx)
(syntax-case stx ()
[(_ c ...)
#'(elem "Shorts for " (racket c ...))
])
)
;; @elem{Shorts for @code{@rawcode}.})